Skip to Content

Report Saving or Email issue - Not enough memory for Operation (Window form .NET application)


We need advise on the below please :

I am using Window Form based application and Crystal Report for reporting part.

So as soon as open the report ,it opens in the report viewer.
And when we click save button or email the attached error is shown. (Not enough memory for Operation)

  • Now please note this error is not coming all the time.When I did a google search I found some information which says to clear the %TEMP% folder. When we clear this folder manually the error is gone. But we can see that if TEMP folder again builds up this error can again appear. I am using Windows10 operation system.
  • I tried using this also ReportDocument.Close and ReportDocument.Dispose method but the problem with this it runs fine but all other operations breaks up for example next and previous button if I press it throws null reference error. So I will not prefer to use these 2.
  • I can use .NET Garbage collector (GC.Collect()) which enforces to clear unmanaged resources from the memory but again it is not recommended to use this,as a part of best practices of .NET.

So question here is -

1. Could you please explain what is the relation between Crystal Report and system's %TEMP% folder. What objects it accumulates in the temporary folder of the system.?

2. Is the Crystal Report has certain memory limit where it accumulates in TEMP folder of the system and finally it does not allow further?

Please help or advise on the same.




save-or-email.png (19.8 kB)
Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Oct 15, 2019 at 02:33 PM

    Crystal doesn't use the Windows disk swap space, it uses its own swap for each report. This goes in the TEMP folder. If you don't call ReportDocument.Close() and ReportDocument.Dispose(), Crystal doesn't clean up the files in this folder. The trick is that you cannot call those until the user is finished with the report. I usually put them in the OnFormClose event handler for the form where the Crystal Viewer is located.

    Also, deep inside the Crystal SDK are a series of COM components. Unfortunately, .NET does NOT memory manage COM components very well, so you do need to call GC.Collect() after disposing of the ReportDocument.

    Crystal also doesn't always clear out the temp files if there is an error that prevents the report from running correctly.

    The trick to lightening the memory load in Crystal is to push as much of the data processing as possible to the database.

    1. Turn on "Use Indexes or Server for Speed" under File >> Options >>Database, which covers all new reports. Also turn it on under File >> Report Options to cover the report you're currently working with.

    2. Don't use Crystal functions in the Select Expert. With the exception of "IsNull()", these generally cannot be pushed to the database for processing. Instead, Crystal will bring all of the data into memory and filter it there. If I'm using tables for the report (instead of a command), I will frequently find a way to use a SQL Expression instead of a Crystal function if I'm going to need the value for filtering data - this way it gets pushed to the database for processing.

    3. Don't combine multiple commands or stored procedures in a single report. Also, don't combine either a command or a stored proc with tables in a report. Thirdly, avoid combining tables from multiple databases in a report. All of these will cause Crystal to pull all of the data into memory and then do the joins there instead of pushing the joins to the database.

    4. If your report is just going to show summary data, but it's aggregating over more than 1,000 or so rows, consider using a command to do the aggregation in the database instead of having Crystal do it in memory. For more information about using commands see my blog post here: Best Practices When Using Commands with Crystal... SCN.

    Crystal will use as much memory as is available before swapping to disk. Then it can use as much disk as is available in the TEMP folder.


    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.