Let me preface this with saying that Crystal Reports is becoming the bane of my existence.
We have several environments:
The Crystal Report pulls data from a SQL server, but the database is different depending on the environment.
There is a config file in the project called connectionStrings.config and the connection string that we use for the website is stored there. The contents of the file looks like this:
To load the report I setup the following class:
The issue is that in my development environment, it is working just fine whereas in the other environments I get the following exception:
Log on failed. No error.
at CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.VerifyDatabase()
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.VerifyDatabase()
at CrystalDecisions.CrystalReports.Engine.ReportDocument.VerifyDatabase()
I verified that the connection is changing by doing the following:
The last step successfully generates the report which tells me that the datasource is changing, otherwise I would expect a logon failure.
What makes this particularly frustrating is that some reports in the non-developing environments work fine whereas some are producing that exception. So I don't understand why it works for some, but not for all.
I've gone through God knows how many SO and SAP forum threads, but the general consensus is that the error is vague and can mean one of a hundred different things went wrong when connecting to the database.
What do y'all suggest in trying to debug this issue?
We have several environments:
- Development
- Azure
- On Prem
The Crystal Report pulls data from a SQL server, but the database is different depending on the environment.
There is a config file in the project called connectionStrings.config and the connection string that we use for the website is stored there. The contents of the file looks like this:
Code:
<connectionStrings>
<add name="dataModel" connectionString="data source=...;initial catalog=...;user id=...;password=...;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>
Code:
public class CrystalReportUtil
{
static string ReportsDirectory = ConfigurationManager.AppSettings["ReportsDirectory"];
private static string ConnectionString = ConfigurationManager.ConnectionStrings["dataModel"].ConnectionString;
public static ReportDocument GetReport(string reportName)
{
var report = new ReportDocument();
var fileDirectory = $"{Utilities.GetProjectRoot()}/Reports";
if (System.Web.HttpContext.Current != null)
{
fileDirectory = System.Web.HttpContext.Current.Server.MapPath(ReportsDirectory);
}
string file = Path.Combine(fileDirectory, $"{reportName}.rpt");
if (!File.Exists(file))
{
throw new System.Exception($"Unable to find report file: {file}");
}
report.Load(file);
var builder = new SqlConnectionStringBuilder(ConnectionString);
var dataSource = builder.DataSource;
var user = builder.UserID;
var password = builder.Password;
var database = builder.InitialCatalog;
report.SetDatabaseLogon(user, password, dataSource, database);
foreach (Table databaseTable in report.Database.Tables)
{
databaseTable.ApplyLogOnInfo(new TableLogOnInfo()
{
ConnectionInfo = new ConnectionInfo()
{
ServerName = dataSource,
DatabaseName = database,
UserID = user,
Password = password
},
ReportName = reportName,
TableName = databaseTable.Name
});
}
report.VerifyDatabase();
return report;
}
}
Quote:
Log on failed. No error.
at CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.VerifyDatabase()
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.VerifyDatabase()
at CrystalDecisions.CrystalReports.Engine.ReportDocument.VerifyDatabase()
- Creating a copy of my datasource
- In the designer, setting the datasource to the copied database
- Deleting the copy
- Previewing the report in the designer fails to load (as expected)
- Generating the report using my utility class
The last step successfully generates the report which tells me that the datasource is changing, otherwise I would expect a logon failure.
What makes this particularly frustrating is that some reports in the non-developing environments work fine whereas some are producing that exception. So I don't understand why it works for some, but not for all.
I've gone through God knows how many SO and SAP forum threads, but the general consensus is that the error is vague and can mean one of a hundred different things went wrong when connecting to the database.
What do y'all suggest in trying to debug this issue?