这个问题给那些有CR经验的人.
设置与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) …Run Code Online (Sandbox Code Playgroud)