Report Design
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Report Design
Message Icon Topic: Log on to crystal report Post Reply Post New Topic
Author Message
kulvijay
Newbie
Newbie


Joined: 17 Feb 2009
Location: India
Online Status: Offline
Posts: 2
Quote kulvijay Replybullet Topic: Log on to crystal report
    Posted: 13 Mar 2009 at 4:49am
Hi, Is there a way to authenticate a user before launching crystal report from a asp.net or winform application?  After authenticating i also want to pass the same credentials to the crystal report tool.

thanks,
Vijay


Edited by kulvijay - 13 Mar 2009 at 4:50am
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 13 Mar 2009 at 12:06pm
Yes.  How you do this depends on whether you're using the CrystalViewer or the ReportDocument object model.
 
For the ReportDocument object model, the C# code look like this:
In PageInit():
    CrystalDecisions.Shared.ConnectionInfo connectionInfo = new CrystalDecisions.Shared.ConnectionInfo();

    connectionInfo.ServerName = qServer;
    connectionInfo.UserID = userID;
    connectionInfo.Password = password;
    // set report connection for main report
    SetDBLogonForReport(connectionInfo, crReport, qServer);
    // set report connection for any subreports
    SetDBLogonForSubreports(connectionInfo, crReport, qServer);
    // view report
    crystalReportViewer.ReportSource = crReport;
-----------
private void SetDBLogonForReport(
    CrystalDecisions.Shared.ConnectionInfo connectionInfo,
    ReportDocument reportDocument,
    string qServer)
{    
  Tables tables = reportDocument.Database.Tables;
     foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
     {
        TableLogOnInfo tableLogonInfo = table.LogOnInfo;
        tableLogonInfo.ConnectionInfo = connectionInfo;
        table.ApplyLogOnInfo(tableLogonInfo);
     }
}
-------------
 
private void SetDBLogonForSubreports(
    CrystalDecisions.Shared.ConnectionInfo connectionInfo,
    ReportDocument reportDocument,
    string qServer)
{
  Sections sections = reportDocument.ReportDefinition.Sections;
  foreach (Section section in sections)
  {
    ReportObjects reportObjects = section.ReportObjects;
      
    foreach (ReportObject reportObject in reportObjects)
    {
      if (reportObject.Kind == ReportObjectKind.SubreportObject)
      {
        SubreportObject subreportObject = (SubreportObject)reportObject;
        ReportDocument subReportDocument =
          subreportObject.OpenSubreport(subreportObject.SubreportName);
        SetDBLogonForReport(connectionInfo, subReportDocument, qServer);
      }
    }
  }
}

I haven't used the CrystalViewer object model, but I'm sure you could find a code snipit it you do a search on the forum.
 
-Dell
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.