I’m having trouble with Crystal Reports database connections using LijsDev.CrystalReportsRunner
in .NET 7 and I had it working in my previous version of the project in .NET Framework.
Problem
On some machines, the .NET Framework version prompts for parameters already supplied in the code and fails to connect to the database. The .NET 7 version works fine on admin machines but non-admin users face connection issues on that sub report specificly because on all other report generation I don’t face these issues and the sub report et main report have the same sql connection.
Details
- ODBC Connection: Verified and connected to the correct database on all machines.
- User Account: Same user account (
User:Password
) is used and has necessary permissions. - Explicit Connection Configuration: Code added to configure the connection for each table in the report.
Key Code
Create Report Method
private Report CreateReport(string reportName, string reportTitle)
{
string serverName = ConfigurationManager.AppSettings["ServerName"];
string databaseName = ConfigurationManager.AppSettings["DatabaseName"];
string userId = "YourUser";
string password = "YourPassword";
var connection = CrystalReportsConnectionFactory.CreateSqlConnection(serverName, databaseName, userId, password);
var report = new Report(reportName, reportTitle)
{
Connection = connection
};
ConfigureReportDatabase(report, serverName, databaseName, userId, password);
return report;
}
private void ConfigureReportDatabase(Report report, string serverName, string databaseName, string userId, string password)
{
foreach (Table table in report.Database.Tables)
{
TableLogOnInfo logOnInfo = table.LogOnInfo;
logOnInfo.ConnectionInfo.ServerName = serverName;
logOnInfo.ConnectionInfo.DatabaseName = databaseName;
logOnInfo.ConnectionInfo.UserID = userId;
logOnInfo.ConnectionInfo.Password = password;
table.ApplyLogOnInfo(logOnInfo);
}
}
Generate Report Code
private void RB_Print_BT_Extra_Click(object sender, EventArgs e)
{
string ParametreList = "";
DataTable Decompte;
if (_idDecompte != 0)
{
Decompte = VariableGlobale._MyConnection.Open("Select * from TabDecompteEntete where IdDecompte=" + _idDecompte + ";");
ParametreList = "IdProjet=" + _idProjet + "&";
ParametreList += "IdDecompte=" + _idDecompte + "&";
ParametreList += "NoDecompte=" + Decompte.Rows[0]["Numero"].ToString() + "&";
ParametreList += "DateDecompte=" + Strings.FormatDateTime(Conversions.ToDate(DateDecompte), DateFormat.LongDate);
(App.Current.MainWindow as MainWindow).CreateRapport(ConfigurationManager.AppSettings["ReportPath"] + "Bordereau.rpt", ParametreList, "Impression " + Text);
}
else
{
Interaction.MsgBox("Il n'y a pas de decompte pour ce bordereau, vous devez avoir au minimum 1 décompte pour imprimer", Constants.vbOKOnly, "Impression du decompte");
}
}
Current Issue
- The .NET Framework version prompts for parameters on some machines (see screenshot).
- The .NET 7 version works correctly on admin machines.
- Non-admin users face connection issues.
- Parameters are supplied in the code (include login info), but the report still prompts for them.
Question
What could be causing this inconsistent behavior? How can I ensure that the connection and report parameters are correctly applied on all machines, regardless of user privileges?
I really wonder why I use the same function everywhere but just for that specific file I have all these issues about connection if all users are able to create a report with other rpt files.
Thanks!
Screenshot
Permission from User base on what the user I sent to the dbconnection info in my report.
Parameters Prompt asked (These prompts are already included in the parameters of the main report but for this subreport instead of taking the parameters from the main report, it wants me to write it manualy
For the translation it says: An external component generate an exception.
Additional Note: Don’t hesitate to ask me question and also I wanted to say that when I replace this sub report by the old one using a dead sql database source the any user can generate the report strangely. I’ve been one week on that issue since CrystalReport is such an old service.