Data Connectivity
 Crystal Reports Forum : Crystal Reports .NET 2003 : Data Connectivity
Message Icon Topic: db login Post Reply Post New Topic
Author Message
sstein
Newbie
Newbie


Joined: 05 Apr 2007
Online Status: Offline
Posts: 5
Quote sstein Replybullet Topic: db login
    Posted: 12 Apr 2007 at 12:10pm
 
I have the below code in my aspx.cs to login to the DB.  The acutal values are stored in web.config.  However, when I changed the IP of the DB to the production DB in my web.config, it keeps prompting me for login information.  The reports are using the old IP.  I then need to go back to CR and change the properties of datasource location for the reports to work.   Why is it ignoring the code below?

private void ConfigureCrystalReports()

{

ConnectionInfo connectionInfo = new ConnectionInfo();

connectionInfo.ServerName = ConfigurationManager.AppSettings["ServerName"];

connectionInfo.DatabaseName = ConfigurationManager.AppSettings["Database"];

connectionInfo.UserID = ConfigurationManager.AppSettings["UserID"];

connectionInfo.Password = ConfigurationManager.AppSettings["Password"];

SetDBLogonForReport(connectionInfo);

CrystalReportViewer.HasCrystalLogo = false;

CrystalReportViewer.HasRefreshButton = true;

}

private void Page_Init(object sender, EventArgs e)

{

ConfigureCrystalReports();

}

private void SetDBLogonForReport(ConnectionInfo connectionInfo)

{

TableLogOnInfos tableLogOnInfos = CrystalReportViewer.LogOnInfo;

foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)

{

tableLogOnInfo.ConnectionInfo = connectionInfo;

}

}

any advice appreciated
ss
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet Posted: 12 Apr 2007 at 3:58pm
Just setting the ConnectionInfo doesn't seem to do the trick.  Here's the code we use inside the foreach loop to do this:

      TableLogOnInfo tableLogonInfo = table.LogOnInfo;
      tableLogonInfo.ConnectionInfo = connectionInfo;
      table.ApplyLogOnInfo(tableLogonInfo);
 
Also, does your report have subreports?  If so, you also have to set their login info as well:
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);
        }
      }
    } 
}
 
-Dell
IP IP Logged
sstein
Newbie
Newbie


Joined: 05 Apr 2007
Online Status: Offline
Posts: 5
Quote sstein Replybullet Posted: 12 Apr 2007 at 11:26pm
i'm using the CrystalReportViewer instead of the reportdocument object model.  the above code is from the "logging onto a secure sql server database" article from the API reference guide and the sample code provided.
 
not sure why it's not working
 
ss


Edited by sstein - 12 Apr 2007 at 11:26pm
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet Posted: 13 Apr 2007 at 6:44am

In general, you're much better off using the ReportDocument object model.  It's more robust.

I've not used the ReportViewer object model, so I'm not sure where to take you from here.  Maybe Brian can answer this one.
 
-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.063 seconds.