Crystal Report10之後,為了系統主機的最佳化,Crystal Report在Server端有了連線數的限制

引述於 Crystal Reports Maximum Report Processing Jobs Limit.pdf

Starting in version 10 of Crystal Reports, the reporting engine was optimized for greatest report throughput.
There are specific registry keys that control this optimization. By default, the print job limit is set to 75 print jobs.

當web主機上開啟報表的job數大於75個job時,就會出現以下的訊息:
已經到達您系統管理員所設定的最大報表處理工作限制。

此時只能下iisreset指令,讓重新啟動iis,才有辨法再執行報表工作。 

網路上大致可以看到兩種解決的方法:

(1).Page_Unload事件:
   在Unload事件中close且dispose開啟報表的ReportDocument物件。

(2).機碼修改:
Crystal Reports 2008 (12.x.x)
HKEY_LOCAL_MACHINE\SOFTWARE\Business Objects\Suite 12.0\Report Application Server\InprocServer\PrintJobLimit
將原本PrintJobLimit預設的75改成-1。

嘗試了(1)做法,對我們來說仍然沒有發揮作用,無法close之前所開啟的ReportDocument。
雖然(2)生效,暫時解決問題,但是我們知道這方法解決不了根本,造成主機資源無法有效適放。

以下是我們的做法:

   1.先宣告一個類別叫RptUtil,並宣告一個全域的Queue用來記錄開啟過的ReportDocument以便未來可以有效地適放資源
   Public Shared doc_queue As Queue  

   2.在開啟報表的程式後,先加入以下的程式碼,立即適放過多的ReportDocument資源,作法是將新增的ReportDocument(下面的例子稱rpt_document)放到Queue裏面,如果Queue的數量大於我們所估計的job數時,原先較早的ReportDocument給Dequeue出來,並適放其資源。註:在debug過程中,發現有一些報表程式會重複開啟兩次ReportDocument,所以建議將queue的count數設小一點,才不會發生無法開啟報表的錯誤。

  '  新增ReportDocument階段
  If IsNothing(rdoc_queue) = True Then rdoc_queue = New Queue
  Me.rpt_document = New ReportDocument
  If IsNothing(rpt_document) = False Then rdoc_queue.Enqueue(rpt_document)


 ' 當完成報表載入工作後, 判斷是否需適放剩餘ReportDocument(允許同一時間至少還有50個job數存在) 
 If RptUtil.doc_queue.Count > 35 Then
   Dim rdoc As ReportDocument = CType(RptUtil.doc_queue.Dequeue(), ReportDocument)
   If IsNothing(rdoc) = False Then 
     rdoc.Close()
     rdoc.Dispose()
   End If
   GC.WaitForPendingFinalizers()
   GC.Collect()
 End If

arrow
arrow
    全站熱搜

    湯瑪的吳 發表在 痞客邦 留言(0) 人氣()