Click here to Skip to main content
15,913,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear all,
I sometimes get the following error while printing crystal report to pdf:
VB
   System.Runtime.InteropServices.COMException (0x80004005): The process cannot access the file because 
it is being used by another process. at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export
(ExportOptions pExportOptions, RequestContext pRequestContext) at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream
(ExportRequestContext reqContext) at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext)
 at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportOptions options) at 
 CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportFormatType formatType) at 
 CommonWA.CommonFunc.GetPDFMemoryStream(DCMSReportDoc _dcmsreportdoc, Boolean& _DataExist) in E:\wwwroot\ASPWA\CommonWA\CommonCom.vb:line 382

The error not occurs frequently but sometimes it will happen, can someone tell me why the error occurs and how can I solve the problem?
Thank you very much.
Ray
Posted
Updated 30-Aug-10 20:32pm
v2

It occurs for the reason the error states - some other code has opened the file and not closed it.
 
Share this answer
 
Hi Christian,
If a file is used by other process, is it the crytal report file being used by other process?
Orignally, I load the report using the default OpenReportMethod. If I change to "OpenReportByTempCopy", is that ok? Moreover, I would like to ask if a temp copy rpt will be generated when I use "OpenReportByTempCopy"? If so, where will be the temp copy will be saved? In temporary internet files or somewhere else?
Thanks,
Ray
 
Share this answer
 
Comments
Christian Graus 31-Aug-10 2:34am    
You should not push 'answer' to ask a question, you can comment, or edit your post. I don't use Crystal Reports, but the error does mean you're trying to save on top of a file that is open, so you need to look at your code that accesses this file and see if there's a method you can use to close it. otherwise you need to save to another file name.
Ray, SWChan 31-Aug-10 21:36pm    
Hi, Christian, Thanks. But I cannot test that out since it will not happen in development server, it only happen in production server. So I would like to ask if anyone has the same problem before and solve that. Thanks.
Ray, did you get any solution to this problem?
 
Share this answer
 
I'm guessing that you are exporting to a PDF name that already exists and is currently open in Adobe Reader. When you export to PDF you may want to first check to see if that PDF name already exists, and if so use another name. Or include a datetime stamp in your PDF name to ensure that it doesn't already exist.
 
Share this answer
 
It probably happens because another user has hit the same page/piece of code, and you always use the same filename for the task. Try using a new GUID for the file name each time the code is hit, or have the code retry after a number of seconds. If my theory is correct, it'll clear itself up after a few seconds, and you'll be allowed to do whatever you're trying to do with the file. If the file is simply being read, you can open it for unexclusive read, and the file can be opened by multiple users at the same time.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900