简体   繁体   中英

How to remove Load Report Failed Error in Crystal Reports version 13.0?

I am developing a simple app using Crystal Report (Version 13.0) and .NET Framework 4.0 as well as VS 2013. What i am doing is that i have a Crystal report viewer on the form which is supposed to show/load my report when button is clicked. My code to load a report is:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
namespace CystalReportsApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                ReportDocument rpt = new ReportDocument();
                rpt.Load(@"e:<path>\CystalReportsApp\CystalReportsApp\CrystalReport1.rpt");
                crystalReportViewer1.ReportSource = rpt;
                crystalReportViewer1.Refresh();
            }
            catch (Exception ex)
            {

                throw;
            }
        }
    }
}

Problem i am getting is that whenever i click button, an exception occurs saying this:

CrystalDecisions.Shared.CrystalReportsException was unhandled
HResult=-2146232832
Message=Load report failed.
Source=CrystalDecisions.CrystalReports.Engine
StackTrace:
   at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
   at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob)
   at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename)
   at CystalReportsApp.Form1.button1_Click(Object sender, EventArgs e) in e:\<path>\CystalReportsApp\Form1.cs:line 32
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at CystalReportsApp.Program.Main() in e:\<path>\CystalReportsApp\Program.cs:line 19
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Runtime.InteropServices.COMException
    HResult=-2147467259
    Message=The system cannot find the path specified.    
    Source=Analysis Server
    ErrorCode=-2147467259
    StackTrace:
         at CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.Open(Object& DocumentPath, Int32 Options)
         at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.Open(Object& DocumentPath, Int32 Options)
         at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
       InnerException: 

Solutions i have tried are:

  1. Checked the path again and again.
  2. Checking file permissions on the temp folder as well as on the folder where my report resides.
  3. Checking stackoverflow for the answer but couldn't find an answer regarding my problem's details.

But all in vein. Can somebody please tell me as what's going behind the scene?

UPDATED Alongside this forum, i had also posted this question at SAP crystal reports' forum for which somebody answered as to just remove @ sign from the path. But as i remove @ sign, "Unrecognized escape sequence" errors come. Please help! Answer by SAP COMMUNITY NETWORK

Try :

Web

 rpt.Load(Server.MapPath("\\CystalReportsApp\\CrystalReport1.rpt"))

Windows

rpt.Load(@"e:\\users\\shahid sultan minhas\\documents\\visual studio 2013\\Projects\\CystalReportsApp\\CystalReportsApp\\CrystalReport1.rpt")

Your problem (like mine) may still be related to the path to the RPT file. In an .aspx Web Form, you might benefit from this syntax:

    <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
        <Report FileName="~/MyCrystalReport.rpt">
        </Report>
    </CR:CrystalReportSource>

By using a relative path, I was able to execute my report files after many hours of trial-and-error.

MySql.Data.MySqlClient.MySqlDataAdapter myAdapter1 = new MySql.Data.MySqlClient.MySqlDataAdapter(ds.Tables[0].Rows[0]["Query"].ToString(), conn);
                    myAdapter1.Fill(myData);
                    WaitSumCrystalReport3 myr = new WaitSumCrystalReport3();
                    myr.SetDataSource(myData);
                    if (myData.Tables[0].Rows.Count > 0)
                        myr.PrintToPrinter(1, true, 1, 10);
                    cmd.CommandText = "Update tbl_print set Status='1' where ID='" + ds.Tables[0].Rows[0]["ID"].ToString() + "'";
                cmd.Connection = conn;
                cmd.ExecuteNonQuery();
//disposing the crystal report object to clear the temp memroy.. otherwise memory is overflow occurs in future
                    myr.Dispose();
//above statement is used to dispose... it will work fine

..

cryRpt.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CrystalReport1.rpt"));

and right click on CrystalReport1.rpt goto properties and set the Build Action to Content and CopyOutputDirectory to Copy if newer..

hope it will help u, thanx

make sure that all your fields are populating properly.

Once I faced this kind of problem, which resolved after removing error in sql query

I use Procmon.exe with filters works fine to me (Access Denied to some folder):

https://stackoverflow.com/a/41942720/1536197

In my case, I first got an error: Could not load file or assembly 'CrystalDecisions.ReportAppServer.ClientDoc', Version=xxx' . And then I find and add reference to the xxx version of CrystalDecisions.ReportAppServer.ClientDoc.dll , then run the program, a new error Load Report Failed occur.

After asking my colleague, I goto Project > Properties > Build , and uncheck the Prefer 32-bit checkbox , and restore to use the original version I use of CrystalDecisions.ReportAppServer.ClientDoc.dll , then I can successfully generate report.

Besides I have installed 64-bit version of Crystal Reports runtime engine .

For ASP.NET Web Project, goto

 Tools
  -> Options
   -> Projects and Solutions
    -> Web Projects
     -> Check "Use the 64 bit version of IIS Express for web sites and projects"`

Reference: How can I force IIS Express to run in 32 bit mode?

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