这个问题给有经验的人。水晶报告和连接问题
我有设置连接到Crystal报告的问题。 我收到了我的客户的报告。他和我的服务器上的数据库结构相同。但服务器和数据库的名称是不同的。 他正在使用“命令”创建报告(在数据库字段 - >数据库专家中添加命令...)。这个命令有一些返回数据的功能。 我尝试在我的计算机上运行此报告,当我尝试执行TestConnectivity()时出现问题,此方法返回false。 我尝试调试,发现应用ApplyLogOnInfo()后,内部对象RasTable具有旧的ConnectionInfo。
我使用的下一个代码组连接:
private void ApplyConnection(ReportDocument report, ConnectionInfo connectionInfo)
{
ApplyLogOnInfo(report, connectionInfo);
ApplyLogOnInfoForSubreports(report, connectionInfo);
}
private void ApplyLogOnInfo(ReportDocument reportDocument, ConnectionInfo connectionInfo)
{
foreach (Table table in reportDocument.Database.Tables)
{
table.LogOnInfo.ConnectionInfo.AllowCustomConnection = true;
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
_log.InfoFormat("Table connection state: TableName = {0}, IsConnect = {1}", table.Name, table.TestConnectivity());
}
}
private void ApplyLogOnInfoForSubreports(ReportDocument reportDocument, ConnectionInfo connectionInfo)
{
Sections sections = reportDocument.ReportDefinition.Sections;
foreach (Section section in sections)
{
ReportObjects reportObjects = section.ReportObjects;
foreach (ReportObject reportObject in reportObjects)
{
_log.InfoFormat("Type = {0}, Name = {1}",reportObject.Name, reportObject.Kind);
if (reportObject.Kind == ReportObjectKind.SubreportObject)
{
var subreportObject = (SubreportObject)reportObject;
ReportDocument subReportDocument = subreportObject.OpenSubreport(subreportObject.SubreportName);
ApplyLogOnInfo(subReportDocument, connectionInfo);
}
}
}
}
所以我的问题是:
- 我怎样才能树立正确连接到命令?
- 为什么我无法更改连接? (如果报告是在其他服务器上创建的)。