首页 文章

如何在Crystal Reports 13.0版中删除加载报告失败错误?

提问于
浏览
1

我正在使用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;
            }
        }
    }
}

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:

  • 一次又一次检查路径 .

  • 检查临时文件夹以及报告所在文件夹的文件权限 .

  • 检查stackoverflow的答案,但无法查看详细信息 .

但一切都在静脉中 . 有人可以告诉我幕后的情况吗?

UPDATED 除了这个论坛之外,我还在SAP crystal reports'论坛上发布了这个问题,有人回答说只是从路径中删除@符号 . 但是当我删除@符号时,"Unrecognized escape sequence"错误就会出现 . 请帮忙! Answer by SAP COMMUNITY NETWORK

6 回答

  • 0

    试试:

    卷筒纸

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

    视窗

    rpt.Load(@"e:\\users\\shahid sultan minhas\\documents\\visual studio 2013\\Projects\\CystalReportsApp\\CystalReportsApp\\CrystalReport1.rpt")
    
  • 2
    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
    

    ..

  • 0

    你的问题(比如我的)可能仍然与RPT文件的路径有关 . 在.aspx Web窗体中,您可能会受益于此语法:

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

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

  • 0

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

    并右键单击CrystalReport1.rpt goto属性并将Build Action设置为Content,将CopyOutputDirectory设置为Copy for new ..

    希望它能帮助你,而不是

  • 0

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

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

  • 0

    我使用 Procmon.exe 与过滤器工作正常(访问被拒绝到某个文件夹):

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

相关问题