水晶报告与子报告不适用于生产/测试机C#winforms
问题描述:
我已经创建了包含8个子报告(使用VS 2010)的水晶报告。我创建了存储过程,它填充了与主报告&子报告链接的所有转储SQL服务器表。我的代码在开发机器上工作正常,但是当部署到另一台机器时,它会抛出以下错误。水晶报告与子报告不适用于生产/测试机C#winforms
无法打开连接。
详细信息:[数据库供应商代码17]
未能打开连接。
rpt_reportName {GUID}。RPT
详细信息:[数据库厂商代码17]
以下是我的代码来生成报告。
ReportDocument crReportDocument;
Boolean TypesDSReports = false;
clsErrorLog oLog = new clsErrorLog();
static TableLogOnInfo crTableLogonInfo;
static ConnectionInfo crConnectionInfo;
static Tables crTables;
static Database crDatabase;
public static void ReportLogin(ReportDocument crDoc, string Server, string Database, string UserID, string Password)
{
crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName = Server;
crConnectionInfo.DatabaseName = Database;
crConnectionInfo.UserID = UserID;
crConnectionInfo.Password = Password;
crDatabase = crDoc.Database;
crTables = crDatabase.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
{
crTableLogonInfo = crTable.LogOnInfo;
crTableLogonInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogonInfo);
}
//crDoc.Subreports["aa"].co = crConnectionInfo;
}
private void DisplayReportWithSubReport()
{
try
{
ReportDocument crReportDocument = new ReportDocument();
crReportDocument.Load(sReportPath.Trim());
ReportLogin(crReportDocument, clsCustomize.gsPropServerName, clsCustomize.gsPropCurrentDataBaseName, clsCustomize.gsPropDataBaseUserID, clsCustomize.gsPropDataBasePassword);
crReportDocument.Refresh();
CRViewer.ReportSource = crReportDocument;
CRViewer.RefreshReport();
this.Text = sDisplayReportCaption;
if (TypesDSReports == false)
{
crReportDocument.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4;
}
this.WindowState = FormWindowState.Maximized;
if (HMS.Common.clsConstants.gbPropCloseReportForm == true)
{
crReportDocument.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4;
if (HMS.clsCustomize.giNoOfPrintCopies == 0)
{
HMS.clsCustomize.giNoOfPrintCopies = 1;
}
crReportDocument.PrintToPrinter(HMS.clsCustomize.giNoOfPrintCopies, false, 1, 1);
HMS.Common.clsConstants.gbPropCloseReportForm = false; //Reset the Flag
this.Close();
}
else
{
this.WindowState = FormWindowState.Maximized;
}
}
catch (Exception ex)
{
oLog.LogError(ex, "", "", "", "");
}
}
开发机器和目标机器都具有相同的系统配置。请大家帮助解决问题。
问候, 维克拉姆
答
我想出了解决方案自己。我在ReportLogin方法中添加了以下代码,并且完美运行。
for (int i = 0; i < crDoc.Subreports.Count; i++)
{
crDoc.Subreports[i].SetDatabaseLogon(UserID, Password, Server, Database);
}
答
我不是100%,但我敢肯定,这是不够的设定只有*别的连接信息。您可以通过您的子报表/表需要循环并应用logonInfo每个
crDoc.Subreports [X] .Database.Tables [Y] .ApplyLogOnInfo(crTableLogonInfo)...
我完全同意乔纳森,我们还需要提供子报告级别的连接信息。我在下面添加了我的代码。 – user2092054