如何在Crystal Reports 13.0版中删除Load Report Failed Error?

时间:2014-11-24 16:02:13

标签: c# .net crystal-reports report reportviewer

我正在使用Crystal Report(版本13.0)和.NET Framework 4.0以及VS 2013开发一个简单的应用程序。我正在做的是我在表单上有一个Crystal报表查看器,它应该显示/加载我的单击按钮时报告。我加载报告的代码是:

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;
            }
        }
    }
}

我得到的问题是,每当我点击按钮时,会发生异常,说:

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: 

我尝试过的解决方案是:

  1. 一次又一次地检查路径。
  2. 检查临时文件夹以及报告所在文件夹的文件权限。
  3. 检查stackoverflow是否有答案,但无法找到有关我的问题详情的答案。
  4. 但是一切都在静脉中。有人可以告诉我幕后的情况吗?

    已更新 除了这个论坛,我还在SAP crystal reports&#39;上发布了这个问题。有人回答的论坛只是从路径中删除@符号。但是当我删除@符号时,&#34;无法识别的转义序列&#34;错误来了。请帮忙! Answer by SAP COMMUNITY NETWORK

7 个答案:

答案 0 :(得分:2)

尝试:

网络

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

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

答案 1 :(得分:0)

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

...

答案 2 :(得分:0)

您的问题(如我的)可能仍与RPT文件的路径有关。在.aspx Web窗体中,您可以从这种语法中受益:

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

通过使用相对路径,我可以在经过多个小时的反复试验后执行我的报告文件。

答案 3 :(得分:0)

cryRpt.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,&#34; CrystalReport1.rpt&#34;));

并右键单击CrystalReport1.rpt goto属性并设置 建立内容和行动 CopyOutputDirectory如果更新则复制..

希望它能帮助你, 感谢名单

答案 4 :(得分:0)

确保所有字段都正确填充。

一旦遇到这种问题,在删除sql查询错误后解决了这个问题

答案 5 :(得分:0)

我使用 Procmon.exe ,过滤器可以正常使用(访问被拒绝到某些文件夹):

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

答案 6 :(得分:0)

就我而言,我首先得到一个错误:Could not load file or assembly 'CrystalDecisions.ReportAppServer.ClientDoc', Version=xxx'。然后我找到并添加对 xxx version of CrystalDecisions.ReportAppServer.ClientDoc.dll 的引用,然后运行程序,出现新错误 Load Report Failed

询问我的同事后,我转到Project > Properties > Build,并取消选中Prefer 32-bit 复选框,然后恢复使用我使用的原始版本CrystalDecisions.ReportAppServer.ClientDoc.dll,然后我可以成功生成报告。

此外我已经安装了 64 位版本的 Crystal Reports runtime engine

对于 ASP.NET Web 项目,转到

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

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