簡體   English   中英

如何清除Crystal Report運行時中的“加載報告失敗”錯誤?

[英]How to remove “Load Report Failed” Error in Crystal Report Runtime?

我在客戶的PC上使用Crystal Reports Runtime 13.0.5在WinForms應用程序中打印賬單。 一切進展順利,直到我的一些客戶開始遇到問題。

一整天的報告生成/打印后,晚上,每次我生成報告時,Crystal Reports都會開始顯示錯誤“加載報告失敗”。

我注意到,我的客戶每天要生成數百個報告,而CR運行時每次生成帳單時都會在temp文件夾中生成臨時文件。 也許整天的數百個臨時文件給CR運行時帶來了負擔,並使其在晚上出現此錯誤。

關閉應用程序並從文件夾中刪除所有臨時文件,可使CR運行時重新開始工作。 我還將Crystal Reports的最大作業限制從注冊表中的75增加到1000。

但是,我無法告訴所有客戶關閉該應用程序,刪除所有臨時文件,然后再次使用該應用程序。 我需要一個永久的解決方案。

或者,如果沒有任何永久性解決方案,是否可以在每次生成報告后刪除臨時文件?

編輯:我試圖處理報告,但沒有成功。 我從主窗體顯示報表對話框,並在報表查看器窗體上設置數據源。 如果在顯示報表查看器窗口之前處理報表,則會出現錯誤“對象引用未設置為對象的實例”。 附加代碼以更好地理解。

主要形式:

if (str1 == "A4Printer")
{
     Frm_ReportViewer _objfrm_ReportViewer = new Frm_ReportViewer();
     DataTable dtDetailsReport = _objCommon.DataGridView2DataTable(dgv_SaleForm, "table");
     SendData _obj = new SendData(_objfrm_ReportViewer.ReceiveSalesDataA4);
     _obj(dtDetailsReport, txt_BillNo.Text, accno, txt_PaidAmount.Text, txt_Balence.Text, txt_TotalAmount.Text, txtdisc.Text);
     _objfrm_ReportViewer.ShowDialog();
     ClearSale();
     MasterClear();
     cmb_CustomerName.Select();
}

在報表查看器表單上:

public void ReceiveSalesDataA4(DataTable dtDetail, string BillNO, string AccNo, string PaidAmount, string Balance, string TotalAmount, string Disc)
{
    CrystalReport.Crt_SaleBill _objReport = new CrystalReport.Crt_SaleBill();
    string CompanyMaster = "SELECT tbl_CompanyMaster.CompanyName, tbl_CompanyMaster.Addressline1, tbl_CompanyMaster.Addressline2, tbl_CompanyMaster.MobileNo1, tbl_CompanyMaster.MobileNo2, tbl_CompanyMaster.Landlineno, tbl_CompanyMaster.VatNo, tbl_CompanyMaster.Tinno FROM tbl_CompanyMaster";
    string CustomerMaster = "SELECT CustomerName,AccNo,Address,PhoneNo,Dat FROM tbl_CustomerMaster WHERE (AccNo = '" + AccNo + "')";

    DataTable dt_CustomerMaster = _objSQLHelper.GetDataTable(CustomerMaster);
    _objReport.Database.Tables["dt_registration"].SetDataSource(dt_registration);
    _objReport.Database.Tables["dt_SalesThermalReport"].SetDataSource(dtDetail);
    _objReport.Database.Tables["dt_CustomerMaster"].SetDataSource(dt_CustomerMaster);
    _objReport.SetParameterValue("BillNo", BillNO);
    _objReport.SetParameterValue("PaidAmount", PaidAmount);
    _objReport.SetParameterValue("Disc", Disc);
    _objReport.SetParameterValue("Balance", Balance);
    _objReport.SetParameterValue("TotalAmount", TotalAmount);

    _objReport.SetParameterValue("cdt", clsVariable.CDate);

    Crt_ReportViewer.ReportSource = _objReport;

}

如果我放_objReport.Dispose(); Crt_ReportViewer.ReportSource = _objReport; 以上,主要格式為_objfrm_ReportViewer.ShowDialog(); 給出錯誤“對象引用未設置為對象的實例”。 所以,我不能在這里處理它。 我正在尋找另一種解決方案。 對於任何錯誤,我深表歉意,我是Crystal Report的新手,對於我的公司來說,此問題太重要了,因為由於“加載報告失敗”錯誤而使客戶煩惱。 先感謝您。

您無需刪除任何臨時文件即可解決此問題。 每次要使用報表而不廢棄它時,都創建一個新的報表實例時,會發生此問題。

考慮以下代碼:

private void button1_Click(object sender, EventArgs e)
{
    for (int i = 1; i <= 1000; i++)
    {
        CrystalReport1 myReport = new CrystalReport1();
        myReport.SetDataSource(MyDataSet);
    }
}

在某些迭代后,這很可能會生成“加載報告失敗”錯誤。 要解決此問題,只需在不再需要該報告時就將其處理。

private void button1_Click(object sender, EventArgs e)
{
    for (int i = 1; i <= 1000; i++)
    {
        CrystalReport1 myReport = new CrystalReport1();
        myReport.SetDataSource(MyDataSet);
        //
        //Some code here
        //
        myReport.Dispose();
    }
}

更好的解決方案是只聲明一次報告變量。 這也將使代碼運行更快。

private void button1_Click(object sender, EventArgs e)
{
    CrystalReport1 myReport = new CrystalReport1();

    for (int i = 1; i <= 1000; i++)
    {
        myReport.SetDataSource(MyDataSet);
    }

    myReport.Dispose();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM