Print Page | Close Window

Garbage Collection

Printed From: Crystal Reports Book
Category: Crystal Reports .NET 2003
Forum Name: Writing Code
Forum Discription: .NET 2003 programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=1205
Printed Date: 03 May 2024 at 5:58pm


Topic: Garbage Collection
Posted By: Dave P
Subject: Garbage Collection
Date Posted: 21 Aug 2007 at 8:21am
I recently had the following error message occur
 
"The maximum report processing job limit configured by your system administrator has been reached"
 
Apparently the error means that there is too much load on the reporting engine. In Crystal X onwards the reporting engine was optimized for greater report throughput, and a default print job limit of 75 was set in the registry. A solution to this problem is to either raise the limit in the registry, or call ReportDocument.Close & ReportDocument.Dispose in the Page_Unload event (the method I chose).
 
The problem is that in my report viewer page, when you click on a navigate button in the viewer to go to another report page, the unload fires which closes and disposes the local report object, but also the one stored in the session. So when the page tries to reload it can't find the report so exceptions. Below is my code:
 
private CrystalDecisions.CrystalReports.Engine.ReportDocument myReport;
 
private void Page_Load(object sender, System.EventArgs e)
{
   
   myReport = (CrystalDecisions.CrystalReports.Engine.ReportDocument)Session["myCrystalReport"];

      myCrystalReportViewer.ReportSource = myReport;
}
 
private void Page_Unload(object sender, System.EventArgs e)
{
       if(myReport != null)
       {
             myReport.Close();
             myReport.Dispose();
       }
 }
 
Any ideas as to how to get around this?
 
Thanks.



Replies:
Posted By: BrianBischof
Date Posted: 21 Aug 2007 at 8:36am
I had a similar problem a while back, and I put the set the Session() object to null on the page that the user goes to after they are finished looking at the report. For example, if you have a reporting menu page, then when that page loads I would check to see if there are any report objects left over in the Session collection and dispose of them. This lets you keep the report objects active while viewing and kill them off once the user has finished.

Please report back how this goes for you. I only needed to do it one time a while back and I want to see how it works for you. Thanks.


-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: Dave P
Date Posted: 23 Aug 2007 at 4:54am
Thanks for replying Brian.
 
I have been able to do as you said and kill off the session objects when no longer needed. However, I have come across something else. I understand that when the Crystal Report Viewer opens a report, it creates a temp .rpt file somewhere on the C drive. In my case it is in the following location:
 
C:\Documents and Settings\<<Computer Name>>\ASPNET\Local Settings\Temp
 
The problem is that this never seems to be cleaned up, and my folder had over 1500 temp .rpt files in it! Would calling Close and Dispose on the report document remove the temp reports from here?
 
I went down this avenue and got an idea from a post I'd seen about creating a factory class to keep track of all report objects created. My class is shown below:
 
public class ReportFactory
{
      public static Hashtable reportTable = new Hashtable();
     
      public static void CreateReport(string key, string path)
      {
            ReportDocument report = new ReportDocument();
            report.Load(path);
            reportTable.Add(key, report);
      }
  
      public static void CloseReport(string key)
      {
            ((ReportDocument)reportTable[key]).Close();
            ((ReportDocument)reportTable[key]).Dispose();
            reportTable.Remove(key);
      }
}
 
In theory I should have all the report objects in one place, and destroy them as and when needed using CloseReport. This doesn't seem to work as expected, and the files are sometimes removed from the temp folder, but sometimes not. I am slightly confused, so any light you could shed on the matter would be greatly appreciated.
 


Posted By: BrianBischof
Date Posted: 23 Aug 2007 at 11:54am
yeah, the tmp files are a problem. Unfortunately, I don't know how to handle them. I just manually clean them up when I come across them. With you having so many on the server, I would write a little program that runs in the background and deletes all tmp files that are two days old. That would keep the folder clean.

In fact, I think I'll go check my own server now....

Yep. 217 temp rpt files on my server. I have a question for you though. I see a lot of "~cpe{guid}.tmp" files as well. Do you know if this is from another application, or is CR creating ~cpe temp files as well? Do you have them also?


-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: BrianBischof
Date Posted: 23 Aug 2007 at 11:55am
I'm going to follow up on this next time I talk to tech support at BOBJ. See what their thoughts are.

-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: jayaaniithaa
Date Posted: 24 Nov 2008 at 12:54pm
I am getting "Load Report Failed" error when the .rpt files in temp folder is not cleaned, even after disposing the reports in Page_Unload event. 
Please let me know the solution if you have solved this issue.


Posted By: jayaaniithaa
Date Posted: 24 Nov 2008 at 12:56pm
I am getting "Load Report Failed" error when the .rpt files in temp folder is more. I am disposing the reports in Page_Unload event also. Sometimes the rpt files are cleared and sometimes not.
Please let me know any solution which helped to resolve this issue.


Posted By: hilfy
Date Posted: 25 Nov 2008 at 12:01pm
Does the error go away when you clear out the temp folder?  How much disk space is available on the drive where the temp folder is located?  I suspect you're running out of disk space.
 
Crystal is notorious for not cleaning up temp files, and has been for years.  Currently the only way around this is to do like Brian suggested and write a program or a .bat file that will go through and delete them - we use a .bat file that is run by the Windows Scheduler which deletes all of the files in the temp folder on Saturday evenings.
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: Manas Sahu
Date Posted: 09 Feb 2012 at 11:27pm
Hi hilfy,
 
I am also facing the similar type of problem of crystal report temp file. These temp are accumulated in the crystal report serer and eatting up huge amount of disk space. Could you please share the .bat file you are talking about. It will be very helpful for me.
 
Thanks in advance. :)


-------------
I can change the world but i do not have the source code.


Posted By: jack_sparrow
Date Posted: 27 Mar 2012 at 8:52am
Go to IIS Manager -> Connections -> Application Pools and select your application and under "Edit Application Pool", click Recycling.

Here you can define a recycling schedule which will remove any rpt or tmp file under Windows\Temp.



Print Page | Close Window