C# CrystalReport 加载报告失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1184309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 10:16:49  来源:igfitidea点击:

CrystalReport Load report failed

c#.netcrystal-reports

提问by mSafdel

I have a windows application project (C# and .NET 2.0) that used Crystal Report 2008. But I get error sometimes (it seems accidentally) in loading report. That error is:

我有一个使用 Crystal Report 2008 的 Windows 应用程序项目(C# 和 .NET 2.0)。但有时我在加载报告时出错(似乎是意外)。该错误是:

CrystalDecisions.Shared.CrystalReportsException: Load report failed.
System.Runtime.InteropServices.COMException (0x8000020D): Unable to load report.
   at CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.Open(Object& DocumentPath, Int32 Options)
   at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.Open(Object& DocumentPath, Int32 Options)
   at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
   --- End of inner exception stack trace ---
   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 SIA.DataTransfer.Forms.frmReport.GetStateReport(Int32 transferType)

please guide me. How can I solve this problem?

请指导我。我怎么解决这个问题?

回答by SeanJA

The internet also suggests reinstalling the crystal report runtimes on the machines you are trying to open the report on (making sure that all locations have the same version).

互联网还建议在您尝试打开报告的机器上重新安装水晶报告运行时(确保所有位置都具有相同的版本)。

回答by John Dyer

If your application is a standalone executable then this error is generated because you are not closing your report object properly when you are done with whatever you do. You might see this error running in your application as an ASP.NET app with a lot of users accessing your site simultaneously.

如果您的应用程序是独立的可执行文件,那么会生成此错误,因为您在完成任何操作后都没有正确关闭报表对象。您可能会看到此错误在您的应用程序中作为 ASP.NET 应用程序运行,并且有大量用户同时访问您的站点。

You can cause the error to appear sooner by tweaking this registry key:

您可以通过调整此注册表项来使错误更快出现:

HKEY_LOCAL_MACHINE\SOFTWARE\CRYSTAL DECISIONS.0\REPORT APPLICATION SERVER\SERVER\PrintJobLimit

It normally is defaulted to 75. For debugging you can set it to a smaller value and cause the error to appear sooner.

它通常默认为 75。为了调试,您可以将其设置为较小的值,从而使错误更快出现。

When you are done using a report object, call the .Close() method which will clean up the un-managed resources used.

使用完报告对象后,调用 .Close() 方法,该方法将清理使用的非托管资源。

There are those that mention to change the setting to -1. This is a mistake, it will only cause other problems for an application that is long running. The process will eventually run out of resources and start to fail in ways that will be even more difficult to troubleshoot.

有些人提到将设置更改为 -1。这是一个错误,它只会对长时间运行的应用程序造成其他问题。该过程最终将耗尽资源并开始以更难以排除故障的方式失败。

回答by spm

FYI, I have just verified this solution for a similar problem. The ReportDocument.Load method was failing when using a mapped network share or UNC path and installing the crystal reports VS runtime on the file server fixed the problem.

仅供参考,我刚刚针对类似问题验证了此解决方案。当使用映射的网络共享或 UNC 路径并在文件服务器上安装 Crystal Reports VS 运行时修复了该问题时,ReportDocument.Load 方法失​​败。

回答by David T. Macknet

I have verified John Dyer'ssolution, above, does not work in all cases.

我已经验证约翰·戴尔的解决方案,上面,在所有情况下无法正常工作。

I have also verified that reinstalling Crystal Runtime did no good for this particular error.

我还验证了重新安装 Crystal Runtime 对这个特定错误没有好处。

For my app this was only happening on Citrix installs of a stand-alone .exe, with embedded reports. Before using the Crystal Report Viewer, I need to make sure that I've cleared out any report previously loaded in the viewer, as per John's instructions. So, I'll wrote something (in VB) which looks like

对于我的应用程序,这仅发生在带有嵌入式报告的独立 .exe 的 Citrix 安装中。在使用 Crystal Report Viewer 之前,我需要确保按照 John 的指示清除了之前加载到查看器中的所有报告。所以,我会写一些东西(在 VB 中),看起来像

Public Function ShowRpt(...) As Boolean
    ....
    CleanOutViewer()
    ....
End Function

where CleanOutViewer is:

CleanOutViewer 在哪里:

Private Sub CleanOutViewer()
    If Not Me.CrystalReportViewer1.ReportSource() Is Nothing Then
        CType(Me.CrystalReportViewer1.ReportSource(), CrystalDecisions.CrystalReports.Engine.ReportDocument).Close()
        CType(Me.CrystalReportViewer1.ReportSource(), CrystalDecisions.CrystalReports.Engine.ReportDocument).Dispose()
        Me.CrystalReportViewer1.ReportSource() = Nothing
        GC.Collect()
    End If
End Sub

The calls after .Close() also had no effect (and were added as an alternate attempt to try to force the Crystal to release resources).

.Close() 之后的调用也没有效果(并且被添加为尝试强制 Crystal 释放资源的替代尝试)。

回答by Jazz

Crystal Report Document needs to be manually disposed.

Crystal Report Document 需要手动处理。

You should control the lifetime of all Reports in your application and call their Dispose before reaching the 75 limit.

您应该控制应用程序中所有报告的生命周期,并在达到 75 个限制之前调用它们的 Dispose。

There is a good approach on how to achieve this in this link:

在此链接中有一个关于如何实现这一点的好方法:

http://geekswithblogs.net/technetbytes/archive/2007/07/17/114008.aspx

http://geekswithblogs.net/technetbytes/archive/2007/07/17/114008.aspx

回答by Emanuele Greco

Increasing CurrentJobLimitis not the solution; this number will be reached if the counter is not reset.
To avoid Job counter increase, you need to close the Crystal Report Document (ReportSource.Close()) programmatically.

增加CurrentJobLimit不是解决方案;如果计数器未复位,则将达到此数字。
为避免作业计数器增加,您需要以ReportSource.Close()编程方式关闭 Crystal Report 文档 ( )。

protected void Page_Unload(object sender, EventArgs e)
 {
    CrystalReportViewer1.ReportSource.Close();
 }

This is the only way to avoid continue increasing of opened report, that are counted by CurrentJobLimit

这是避免继续增加打开的报告的唯一方法,这些报告由 CurrentJobLimit

回答by Muhammad Ashhar Hasan

I solved it, had the same issue. I went to report properties and set "buildAction" to "Content".

我解决了,有同样的问题。我去报告属性并将“buildAction”设置为“Content”。