Print Page | Close Window

db login

Printed From: Crystal Reports Book
Category: Crystal Reports .NET 2003
Forum Name: Data Connectivity
Forum Discription: How to connect to data sources and export reports
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=515
Printed Date: 04 May 2024 at 8:54pm


Topic: db login
Posted By: sstein
Subject: db login
Date 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



Replies:
Posted By: hilfy
Date 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


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: sstein
Date 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


Posted By: hilfy
Date 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


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics



Print Page | Close Window