locked
Crystal report load report error RRS feed

  • Question

  • User1339516451 posted

    when i click on button then an error occure Load report failed.

    My code is:

        ReportDocument cryrpt = new ReportDocument();
    
      private void button1_Click(object sender, EventArgs e)
            {
                    SqlConnection sqlcon = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=Company;Integrated Security=True");
                    SqlDataAdapter dap = new SqlDataAdapter("select * from tbl_addemp", sqlcon);
                    DataSet ds = new DataSet();
                    dap.Fill(ds, "tbl_addemp");
    
                    cryrpt.Load("~/CrystalReport1.rpt");
                    cryrpt.SetDataSource(ds);
                    crystalReportViewer1.ReportSource = cryrpt;
            }

    Monday, December 9, 2013 2:21 PM

All replies

  • User-1818759697 posted

    Hi,

    This error occurs in the following scenarios.  

    Permission issue The application must have access to the Temp folder. You have two choices to solve this (Choose any one).

    1. How to Assign Permissions for the Windows Temporary Folder on the Web Servers[^]
    2. ASP.NET Impersonation[^]

    ASPNET machine account to be added to the Temp directory, so we have to specify username and password attributes for <identity> tag in Web.config file for identifying the IIS Authenticated Account or User.</identity>

    <identity impersonate="true" userName="accountname" password="password" />

    Invalid File path or File name

    • Ensure the Report file name is correct (may be Typo or something. Example: Repotr1.rpt instead of Report1.rpt)
    • Ensure the Report path is correct (Example: "Reports/Report1.rpt" instead of "~/Reports/Report1.rpt")
    • Actually some of us forget to copy the report files to the publish folder (IIS virtual directory) so copy it.

    Unmanaged resources We must clean up the unmanaged resources(ReportDocument object) used in the page like below.

     
    protected void Page_Unload(object sender, EventArgs e)
    {
      if(RptDoc != null)
      {
        RptDoc.Close();
        RptDoc.Dispose();
      }
    }

    For more information, you could refer to:

    http://www.codeproject.com/Tips/297119/Crystal-Reports-Fix-for-Load-report-failed-error

    http://www.codeproject.com/Tips/76819/Crystal-Reports-Fix-for-Load-report-failed-error

    Regards

    Tuesday, December 10, 2013 11:48 PM
  • User1815411410 posted

    hi manish,

    have you made sure you are using the correct crystal report version on your code?

    besides, you also need to make sure that the application pool is set to operate under LOCAL SERVICE permission. Additionally, please make sure you copy the crystalreportviewer folder to your working folder.

    Please mark this response as "answer" it helps you. Thanks heaps!

    Wednesday, December 11, 2013 1:51 AM