简体   繁体   English

如何管理Crystal Report Dispose?

[英]How to manage Crystal Report Dispose?

In the Visual Studio 2012 version of Crystal Reports 13 there is a threshold that throttles concurrent reports, this also includes sub reports, to 75 reports across a machine. 在Visual Studio 2012版本的Crystal Reports 13中,有一个阈值可以限制并发报告,这也包括子报告,以及计算机上的75个报告。 This means if there are 5 web applications on a given server all opened reports across all 5 web applications counts toward the 75 report limit. 这意味着如果给定服务器上有5个Web应用程序,则所有5个Web应用程序中的所有打开的报告都会计入75报告限制。

The error manifests itself in different ways and may result in the following errors “Not enough memory for operation.” or “The maximum report processing jobs limit configured by your system administrator has been reached”. 该错误以不同方式显示,可能导致以下错误“操作内存不足。”或“已达到系统管理员配置的最大报告处理作业限制”。

The problem is the reports are not disposed and they continue accumulate until the 75 limit is hit. 问题是报告没有处理,它们会继续累积,直到达到75限制。 To fix this issue, the reports have to be disposed of at the earliest possible time. 要解决此问题,必须尽早处理报告。 This sounds simple, but is not as straightforward as it seems. 这听起来很简单,但并不像看起来那么简单。 Depending how the reports are generated there are two scenarios: First is generating PDF's or Excel spreadsheets and the second is using the Crystal Report Viewer. 根据报告的生成方式,有两种情况:第一种是生成PDF或Excel电子表格,第二种是使用Crystal Report Viewer。 Each scenario has a different lifetime, which we need to take into account when crafting our solution. 每个场景都有不同的生命周期,我们在制定解决方案时需要考虑这些生命周期。

       private bool disposed = false;

        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    context.Dispose(); //context means your crystal report document object.
                }
            }
            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

SOLVED 解决了

CurrentJobLimit is a counter of concurrent reports. CurrentJobLimit是并发报告的计数器。
This counter is not well managed, so it can easily increase, also if real number of reports is lower. 此计数器管理不善,因此如果实际报告数较少,它也可以轻松增加。

I solved the problem closing the Crystal Report Document programmatically . 我解决了以编程方式关闭Crystal Report Document的问题。

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

Anyway, the number of 75 can be increased by registry: 无论如何,注册表可以增加75的数量:

   HKEY_LOCAL_MACHINE\SOFTWARE\CRYSTAL DECISIONS\10.0\REPORT APPLICATION SERVER\SERVER\PrintJobLimit

(but this is just a workaround....) (但这只是一种解决方法....)

I've got a old piece of code that was auto-generating the host WinForm form for Crystal Reports, that had a specific line to call Close() on the report class as the form was closing, I'm pretty sure that was because of disposing issues. 我有一段旧代码,它自动生成Crystal Reports的主机WinForm表单,当表单Close() ,它有一个特定的行来调用报表类的Close() ,我很确定这是因为处理问题。 So might be the case here? 那么可能就是这种情况?

This was probably for an older version of Crystal too, so might be a red herring. 这可能也适用于旧版Crystal,因此可能是红鲱鱼。

I think you should try 我想你应该试试
- rep.Close() - rep.Close()
- rep.Dispose() - rep.Dispose()
- CrystalReportViewer1.Dispose() - CrystalReportViewer1.Dispose()

*my function *我的功能

Protected Sub close_and_dispose_report(ByRef r As ReportDocument)
        If Not r Is Nothing Then
            r.Close()
            r.Dispose()
            CrystalReportViewer1.Dispose()
        End If
    End Sub

when navigate to other page 导航到其他页面时

Protected Sub Page_Unload(sender As Object, e As EventArgs) Handles Me.Unload
        Me.close_and_dispose_report(rep)
End Sub

when close web page 当关闭网页时

Protected Sub Page_Disposed(sender As Object, e As EventArgs) Handles 
        Me.Disposed
        Me.close_and_dispose_report(rep)
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM