I created a Crystal Report using VS 2010 (CRforVS_13_0_4.exe was used to install CR for VS). I have a class that I use for data access. This class loads the data into variables that are public members of the class. When I created the report using the Database Expert, I chose My Connections and selected the class I defined (CVLData) as the Table. I then selected all the fields from the class that I need on the report. When the user clicks a button to load the report, the data is loaded into the class for the report. When the report is displayed I get an error: Database logon failed. When I set EnableDatabaseLogonPrompt to True I get a prompt for database credentials. Since the data is already loaded into the class I don't know why I am being prompted for database credentials.
I created a DataSet with the tables that I need for the report and used that as my DataSource. I still am prompted for credentials. I added the following code to set the credentials and I still have the problem.
protected void VerifyCVL_Click(object sender, EventArgs e)
{
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load(Server.MapPath("test.rpt"));
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "my server";
connectionInfo.DatabaseName = "my db";
connectionInfo.UserID = "userid";
connectionInfo.Password = "password";
SetDBLogonForReport(connectionInfo, cryRpt);
CrystalReportViewer1.ReportSource = cryRpt;
CrystalReportViewer1.RefreshReport();
}
private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
{
Tables tables = reportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
tableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
}
}
If I use a report that contains text and no data fields, the report displays fine without any prompt for credentials. Can someone please tell me what I am doing wrong?