on 11-07-2012 7:16 PM
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?
The most likely reason for the database prompts / errors is that the dataset is not what the report is expecting.
The connectionInfo code will never work as for a dataset there are no credentials...
I'd recommend having a look at the following:
Crystal Reports Guide To ADO.NET
Crystal Reports for Visual Studio 2005 Walkthroughs (this will apply to any version of CR)
Sample app csharp_win_adodotnet.zip here: http://wiki.sdn.sap.com/wiki/x/JQBmBQ
And for troubleshooting tips, see the blog Troubleshooting Issues with VS .NET Datasets and Crystal Reports
The developer help files may also help:
SAP Crystal Reports .NET API Guide
SAP Crystal Reports .NET SDK Developer Guide
Report Application Server .NET SDK Developer Guide
Report Application Server .NET API Guide
- Ludek
Follow us on Twitter
Got Enhancement ideas? Try the SAP Idea Place
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.