2014-11-24 72 views
1

我正在开发一个使用Crystal Report(版本13.0)和.NET Framework 4.0以及VS 2013的简单应用程序。我所做的是我在窗体上有一个Crystal报表查看器,用于显示/加载我的报表当按钮被点击时。我的代码加载报告:如何在Crystal Reports版本13.0中删除加载报告失败错误?

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,但无法找到有关我的问题的详细信息的答案。

但都是静脉曲张。有人可以告诉我,幕后发生了什么?

修订 除了这个论坛,我也张贴在SAP水晶报表论坛这人回答是刚刚从路径删除@符号这个问题。但是当我删除@符号时,出现“无法识别的转义序列”错误。请帮忙! Answer by SAP COMMUNITY NETWORK

+0

我已经设置Crystalreport的生成操作属性设置为内容,并复制到输出目录“一直拷贝” ...... – Sameer 2014-11-24 16:09:25

+1

你能告诉我们线19,请在你的代码? – 2014-11-25 06:46:52

+0

19号线没有任何东西。为了您的方便,我将把我所有的代码(包含37行)。 – Sameer 2014-11-25 14:19:39

回答

1

尝试:

网络

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

的Windows

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

Sir应该使用Windows窗体应用程序吗? – Sameer 2014-11-25 14:41:27

+0

@Sameer i've更新我的答案 – 2014-11-25 15:17:51

+0

先生没有像在不具有文件夹称为TA_Virdi和报告,并与一个名字CryrepAttendanceReport.rpt没有报告我的系统你没有这样的路径。如果有,请提供有效答案。由于 – Sameer 2014-11-25 15:36:55

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 

..

+1

请提供你的关心一些解释 – Lrrr 2014-12-13 07:26:49

+0

感谢先生,但是现在我把上向前迈进了一步。我已经放弃了Crystal Report,因为它没有办法。所以我想用替代品(简单但功能),我能找到的最佳选择是由cpp提供的Reportmax。它的美妙与合作。我会建议每个人都试一次。 – Sameer 2014-12-13 15:16:23

0

您的问题(像我)可能仍然是RELA指向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转到属性右键点击设置 生成操作内容和 CopyOutputDirectory复制是否有更新..

希望这将有助于U, 感谢名单

+0

这里路径是从System.IO; – Sushil 2016-05-18 09:52:14

0

确保所有您的字段正确填充。

有一次,我遇到这样的问题,这在SQL查询消除误差以后解决

相关问题