cancel
Showing results for 
Search instead for 
Did you mean: 

Temp files locked and never deleted

0 Kudos

This morning I've received form a service that create automatically reports an alert with the following exceptions attached:

I'm using Crystal Report v.13.0.12.1494.

Exception:System.IO.IOException

Message:File exist.

StackTrace:   in System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

   in System.IO.Path.InternalGetTempFileName(Boolean checkHost)

   in CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)

   in CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext)

   in CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext)

   in CrystalDecisions.CrystalReports.Engine.ReportDocument.Export(ExportOptions options)

This exceptions is documented in .NET and is  raised when the temp directory reach the limit of 65535 files.

In my case the directory was not the windows/temp but the c:Users/Administrator/AppData/Local/Temp

The directory was full of .tmp and .rpt files created from Crystal Report when is called the function ReportClass.Export(ExportOptions expOptions)

Cleaning the directory I've notice that many files was locked by the service from the last start.

What I'm asking is why crystal report doesn't delete the tmp files periodically, or immedialtlly after has been created?

Could be this lock also the source of the error 'The maximum report processing jobs limit configured by your system administrator has been reached'?

Edika

Accepted Solutions (1)

Accepted Solutions (1)

former_member188030
Active Contributor
0 Kudos

Hi Edika,

CR does not delete the files automatically, you need to add the CR cleanup code to your app.

use ReportDocument.Close and ReportDocument.Dispose methods to delete the temp files and free the memory.

Yes, insufficient memory in Temp folder can be a cause of the print job limit error.

See this article.

http://scn.sap.com/community/crystal-reports-for-visual-studio/blog/2014/04/25/what-exactly-is-maxim...

- Bhushan

Senior Engineer

SAP Active Global Support

Follow us on Twitter

Got Enhancement ideas? Try the SAP Idea Place

Getting started and moving ahead with Crystal Reports .NET applications.

0 Kudos

In my code I close and dispose the ReportClass object but the temp file are not deleted and are still locked.

This is a sample code I use to do the job:

ReportClass report = null;

report = new OrderReportLB();

report.SetDataSource(ds);

report.PrintOptions.PaperSize = PaperSize.PaperA4;

DiskFileDestinationOptions diskopt = ExportOptions.CreateDiskFileDestinationOptions();

diskopt.DiskFileName = "choosedfilename.pdf";

ExportOptions expopt = new ExportOptions();

if (extension == ".doc")

    expopt.ExportFormatType = ExportFormatType.WordForWindows;

else

    expopt.ExportFormatType = ExportFormatType.PortableDocFormat;

expopt.ExportDestinationType = ExportDestinationType.DiskFile;

expopt.ExportDestinationOptions = diskopt;

report.Export(expopt);

report.Close();

report.Dispose();

How can I dispose and close the ReportDocument if I use the ReportClass object?

Edika

0 Kudos

Hi Edika,

Likely what is happening is your Anti-virus software is blocking the OS from deleting the files. And make sure the process has full admin rights, CR requires read/write permissions on the temp folder.

The way it works is when CR exports it first attempts to create the file in the \temp folder, if that works then it tries to delete it. Once that happens and is successful then CR knows it has full access and now it creates the output and temp files. This part is working or you would not get output files.

When the process is completed it them tells the OS to delete the files so it can create new ones with potentially the same temp file name, the OS actually handles that part.

So if you have files left over it's not CR causing the problem but third party software, typically the AV software or possibly the Firewall. Add your applications EXE to the list of trusted programs and then the temp files should start being removed with you close the report.

Try right clicking on on your EXE and selecting Run As Administrator and see if that helps. Look in your AV logs, I'm sure you'll see it is blocking deletion.

Don

0 Kudos

It is not a program but a windows service that runs under Domain\Administrator account.

I've check in the antivirus log and there is not any alert regarding the windows service.

Moreover the files are created in c:\Users\Administrator.domain\AppData\Local where the service has full control.

The same library is used under a website, and the files are created in c:\windows\temp, but also in this case the temp files are not deleted and are locked.

To avoid the problem of 'report processing jobs limit' I restart the service every night, but it's only a workaround.

I would like to solve the problem definitely.

Is there any debug mode can I activate to check what is failing when I call Close() and Dispose()??

Edika


A little update: 


I've restarted the service and all the .TMP files were deleted, but not the .RPT files, that are the bigger ones: 4592KB vs 1KB of .TMP.

The service use the methos ReportClass.Export to generate the reports.

Restarting the WebSite, that use the method ReportClass.ExportToStream, and write into the windows\temp directory the files were all deleted.

What I think is that the Dispose() method doesn't really dispose the object until the application is closed, leaving some files undeleted.


0 Kudos

So after having established that is not an antivirus problem, anyone can tell me how to debug the Close() and Dispose() methods?

Thanks

former_member183750
Active Contributor
0 Kudos

I wonder if process monitor would show if the app even tries to delete the temp file once close/dispose is called.

Also you initialize the report as:

ReportClass report = null;

Can you please try the following?

ReportClass report = new ReportClass();

- Ludek

Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow us on Twitter

0 Kudos

Hi Edika,

First off, don't use the class, declare the report object this way, the Class is not actually noted in our Reference material:

CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

Second is you need to make sure you are keeping the objects in scope. So when you dispose you need to re-instantiate the report object again.

This should tell the OS those files can be deleted.

Also, call GC.Collect to force the OS to free up the objects.

Should be true for your WEB app also.

Although there are issue with Objects in a WEB app, you need to call a Java Script file to actually close/dispose the objects. A quick Google search by Ludek found this info:

javascript to check when the browser window is close - Stack Overflow

Don

0 Kudos

It looks that using ReportDocument instead of ReportClass the dispose operation end successfully and the temp files are deleted.

Many Thanks

Answers (0)