简体   繁体   中英

Report takes too long to load when first run

When I debug my project and view my report, it takes too much time to load - at least a minute or two. When I reload the same report and run it a second time, it works properly with no load time. How can I reduce the loading time?

ReportDocument reportDocument = new ReportDocument();
TableLogOnInfos tableLogOnInfos = new TableLogOnInfos();
TableLogOnInfo tableLogOnInfo = new TableLogOnInfo();
ConnectionInfo connectionInfo = new ConnectionInfo();
try
{
    string startupPath = Application.StartupPath;
    string filename;
    filename = startupPath + "\\Report\\" + rptSettings;
    reportDocument.Load(filename);
}
catch (Exception ex)
{
    KryptonMessageBox.Show(ex.Message, "Error Occured", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
}
connectionInfo.ServerName = Program.serverName;
connectionInfo.DatabaseName = Program.dbName;
connectionInfo.UserID = Program.saName;
connectionInfo.Password = Program.pw;
Tables tables = reportDocument.Database.Tables;
foreach (Table table in tables)
{
    tableLogOnInfo = table.LogOnInfo;
    tableLogOnInfo.ConnectionInfo = connectionInfo;
    table.ApplyLogOnInfo(tableLogOnInfo);
}

string month = "";
month = BillingMonth + " " + DateTime.Now.Year;
reportDocument.SetParameterValue("dueDate", paraDue);
reportDocument.SetParameterValue("feeMonth", BillingMonth);
reportDocument.SetParameterValue("tuitionFee", TutionFee);
reportDocument.SetParameterValue("TotalFee", Total);
reportDocument.SetParameterValue("issueDate", Total);
reportDocument.SetParameterValue("class", Total);
reportDocument.SetParameterValue("fatherName", Total);
reportDocument.SetParameterValue("studentName", Total);
reportDocument.SetParameterValue("annualCharges", Total);
reportDocument.SetParameterValue("validTill", Total);
reportDocument.SetParameterValue("ArrearsFee", Total);
reportDocument.SetParameterValue("JunJulFee", Total);
reportDocument.SetParameterValue("Fine", Total);
reportDocument.SetParameterValue("Discount", Total);
//reportDocument.RecordSelectionFormula = "{tblRegistration.id}=" + ID;

try
{
    if (!printAll)
    {
        crystalReportViewer1.ReportSource = reportDocument;
    }
    else
    {
        reportDocument.PrintToPrinter(1, true, 1, 1);
        sNo++;

    }

}

(This is a shot in the dark, i would've wrote a comment but i am not allowed to.)

Have you tried to unset the printer in your report? Check "No printer (optimize for screen display)" in the "Page Setup" dialog.

I once had an issue with reports that were looking for (network-)printers, resulting in very long startup/loading times.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM