SAP Knowledge Base Article - Public

1892901 - Unexpected error when multiple threads access the same Crystal Report with ExportToStream method

Symptom

  • When multiple processes or threads accessing the ExportToStream method to export the same report to other formats at the same time, two kinds of errors are observed:
    • Error 1: Error in File XXX{XXX}.rpt: Disk full.
    • Error 2: The process cannot access the file because it is being used by another process. 
  • Error 1 only happens when using ExportToStream to generate PDF format files. 
  • Error 2, it is observed for all other export file types
  • code used:

 

ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)

Environment

  • SAP Crystal Reports, developer version for Microsoft Visual Studio
  • Microsoft Visual Studio

Reproducing the Issue

  1. Create a web service project and use this web service to export a Crystal Report. Sample of export code:            
               
    String path = "<the folder where the CR is saved>";
    ReportDocument doc = new ReportDocument();
    doc.Load(path);
    Stream exportFileStream = doc.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); // here format can be changed to other types
     
  2. Create a client application to access the web service method, in this application create multiple threads and make sure they would access the web service function at the same time.
  3. Running the client application will result in the exception on the ExportToStream function.
  4. If the client uses 1 thread to access the web service at a time, there is no exception and everything works fine.

Cause

  • This problem is a limitation in the Crystal Report .NET Runtime as it doesn't allow multiple threads or processes to access the same Crystal report at the same time.
    It has been identified and logged under Problem Report ID ADAPT01666871 to the development team. However it is finally judged as product limitation for the reason above.
  • For error 1: Error in File XXX{XXX}.rpt: Disk full. It is the same cause however it only happens in PDF generation. This is because when exporting to PDF, the fonts in the report are embed to PDF, so the code will access the font to read it. When multiple processes access the font at the same time, a system error ERROR_SHARING_VIOLATION comes, it’s an error described as  “The process cannot access the file because it is being used by another process”. Then the error is transferred and thrown as CFileException::sharingViolation, but when the code catch the CFileException type exception, it treats all this type of errors as Disk Full. As EXCEL(xls), WORD(doc) or other format like TEXT(txt) don’t need to embed the font, so error “Disk full” won’t happen when exporting to these formats. And in the future Service Pack 7 for "SAP Crystal Reports, developer version for Microsoft Visual Studio". It is planned to change this error text to the same with error 2: The process cannot access the file because it is being used by another process.
  • Service pack 7 ETA: September 2013 or later

Resolution

  • Upgrading the Crystal Reports for .NET Runtime to Support Pack 7 or higher. It will resolve the misleading error message Error 1: Error in File XXX{XXX}.rpt: Disk full. problem. In the above case, exporting to all the format will get the same error as: The process cannot access the file because it is being used by another process.
  • Change the program logic and make sure ONLY 1 session/thread is running to access the same Crystal Report document.

Keywords

CR.NET, C#, VB, Visual Studio, VS, 2008, 2010, ADAPT, 1666871, 01666871, Export, Save, multi, simultaneous, parallel , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , Problem

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio