嘿,我正在尝试查看水晶报表 WinForms .net Framework 4.8 应用程序。我已尝试在 ReportDocument 的连接信息中使用 DSN 和服务器名称,但会引发相同的错误,我正在使用 SQL Server 2019 Express Edition。
ReportDocument SetReportLogIn(ReportDocument reportDocument, string MainDbName, string ServerName, string SQLUserName, string SQLPassword)
{
ConnectionInfo ci = new()
{
ServerName = ServerName,
DatabaseName = MainDbName,
UserID = SQLUserName,
Password = SQLPassword,
IntegratedSecurity = false,
Type = ConnectionInfoType.SQL,
};
TableLogOnInfo logonInfo;
foreach (Table table in reportDocument.Database.Tables)
{
logonInfo = table.LogOnInfo;
logonInfo.ConnectionInfo.ServerName = ci.ServerName;
logonInfo.ConnectionInfo.DatabaseName = ci.DatabaseName;
logonInfo.ConnectionInfo.UserID = ci.UserID;
logonInfo.ConnectionInfo.Password = ci.Password;
logonInfo.ConnectionInfo.Type = ci.Type;
logonInfo.TableName = table.Name;
logonInfo.ConnectionInfo.IntegratedSecurity = ci.IntegratedSecurity;
table.ApplyLogOnInfo(logonInfo);
}
foreach (ReportDocument SubRpt in reportDocument.Subreports)
{
TableLogOnInfo SubLogonInfo;
foreach (Table table in reportDocument.Database.Tables)
{
SubLogonInfo = table.LogOnInfo;
SubLogonInfo.ConnectionInfo.ServerName = ci.ServerName;
SubLogonInfo.ConnectionInfo.DatabaseName = ci.DatabaseName;
SubLogonInfo.ConnectionInfo.UserID = ci.UserID;
SubLogonInfo.ConnectionInfo.Password = ci.Password;
SubLogonInfo.ConnectionInfo.IntegratedSecurity = ci.IntegratedSecurity;
SubLogonInfo.ConnectionInfo.Type = ci.Type;
SubLogonInfo.TableName = table.Name;
table.ApplyLogOnInfo(SubLogonInfo);
}
}
// reportDocument.VerifyDatabase();
return reportDocument;
}
即使使用此代码或
reportDocument.SetDatabaseLogon(user: "myUser", password: "myPass", server: ServerName, database: MainDbName, ignoreCase: true);
也是相同的错误
也许您的应用程序(64 位或 32 位)与 ODBC DSN(64 位或 32 位)不匹配。
此外,您使用的 ODBC 驱动程序和 Crystal Runtime 版本是什么?并非所有驱动程序都与所有运行时版本兼容。