ReportDocument.Load() 在 c#.net 中加载 .RPT 文件花费了太多时间

问题描述 投票:0回答:1
ReportDocument cryRpt = new ReportDocument();

SqlCommand MyCommand = new SqlCommand();

SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(cn.ConnectionString);
ConnectionInfo crConnectionInfo = new ConnectionInfo();

TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
string mtmptbl = "TmpAccountReport";

string qrySelBalanceSheet = "select * from tbl_TmpLedgerReport " + System.Environment.NewLine;

MyCommand = new SqlCommand(qrySelBalanceSheet, cn);
MyCommand.CommandType = CommandType.Text;

cn.Open();
MyCommand.ExecuteNonQuery();
cn.Close();

crystalReportViewer1.RefreshReport();
string crReportPath = Application.StartupPath.Replace("bin\\Release", "") + "\\Report";
cryRpt.Load(crReportPath + "\\LedgerAccountReport.rpt");

builder.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["con"];
string dbName = builder.InitialCatalog;
string dbDataSource = builder.DataSource;
string userID = builder.UserID;
string pass = builder.Password;
crConnectionInfo.ServerName = dbDataSource;
crConnectionInfo.DatabaseName = dbName;
crConnectionInfo.UserID = userID;
crConnectionInfo.Password = pass;

Tables Crtables;

Crtables = cryRpt.Database.Tables;

foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in Crtables)
{
    crtableLogoninfo = CrTable.LogOnInfo;
    crtableLogoninfo.ConnectionInfo = crConnectionInfo;
    CrTable.ApplyLogOnInfo(crtableLogoninfo);
}

crystalReportViewer1.ReportSource = cryRpt;                

根据我的代码,我通过 C# 中的 sap crystal reports 显示报告。现在,在某个时间点,我的代码在这一行卡住了 2-3 分钟

cryRpt.Load(crReportPath + "\\LedgerAccountReport.rpt");

(我通过调试代码看到),因此加载报告需要更多时间。

令人惊讶的是,这种情况有时只发生在工作之间。

有什么办法可以解决这个问题吗?

c# .net crystal-reports desktop-application rpt
1个回答
0
投票

几年前,我遇到过类似的问题,每次从 .NET 应用程序内调用时,报告都会呈现缓慢的速度。我尝试在应用程序启动时加载虚拟报告,但没有太大效果。事实证明,Crystal 组件尝试连接一个被我客户的防火墙设备阻止的 verisign URL,因此 Crystal 一直等到该连接超时。 因此,我建议您查看网络流量,或者检查当应用程序在没有防火墙限制的环境中运行时问题是否仍然存在。

© www.soinside.com 2019 - 2024. All rights reserved.