Skip to Content
Former Member
Sep 18, 2017 at 12:50 PM

Problem exporting .rpt to PDF or Excel

934 Views Last edit Sep 18, 2017 at 02:48 PM 4 rev


I am using VS 2015 version 14 update 2
Crystal Reports for VS and runtime engine(
Windows Forms application.
Targetting .Net Framework 4.5.2

I am having a real problem with trying to reliably export a crystal report (to a pdf or xls) in
I programatically create a report in my code based on an existing report (which was created in Visual Studio).
The existing report has sub reports (all verified and data source confirmed to be looking at data tables in datasets in my visual studio application).
I independently retrieve data from SQL server and put this data into tables.
I then set the datasources of the subreports to the  tables  with the populated SQL data.
(not sure if this is the best approach but it works OK in terms of creating a report).
After exporting I close and dispose of the report and all objects in the winform and close and dispose of the winform itself.
I then recreate the winform and try to export again - this process can work up to a few times but I eventually get an error.
The problem only occurs on the export function.
I can load the report repeatedly without issue (if I dont try to export).
I am using the '.export' function for crystal reports:

    Public Sub ExportToExcel()
        Dim d As DateTime
        d = LabelShiftStart.Text.Trim
        Dim s As String = d.ToString("ddMMMyyyy_HHmm")
            Dim CrExportOptions As ExportOptions
            Dim CrDiskFileDestinationOptions As New _
            Dim CrFormatTypeOptions As New ExcelFormatOptions
            ShiftReportNameAndPathExcel = "C:\iLine Reports\Report_" & s.Trim & ".xls"
            CrDiskFileDestinationOptions.DiskFileName =
                                            "C:\iLine Reports\Report_" & s.Trim & ".xls"
            CrExportOptions = objRpt.ExportOptions
            With CrExportOptions
                .ExportDestinationType = ExportDestinationType.DiskFile
                .ExportFormatType = ExportFormatType.Excel
                .DestinationOptions = CrDiskFileDestinationOptions
                .FormatOptions = CrFormatTypeOptions
            End With
            ' check first in case file already exists
            If Not File.Exists(ShiftReportNameAndPathExcel) Then ' only export if file name does not already exist
            End If
        Catch ex As Exception
            TraceUpdate(TimeOfDay.Now.ToString("dd/MMM/yy HH:mm:ss:fff") & "Failure to export to Excel." & ex.ToString.Trim)
        End Try
    End Sub
The first export works without issue always. but subsequent (sometimes second or later) have resulted in the following error:
16/Sep/17 20:59:26:046SHIFT REPORT Failure to export to pdf.CrystalDecisions.CrystalReports.Engine.DataSourceException: Error in File CrystalReportShift 4312_4644_{0DFEA3E2-2AC7-4E57-AC88-FE9A3A722F51}.rpt:
The table could not be found. ---> System.Runtime.InteropServices.COMException: Error in File CrystalReportShift 4312_4644_{0DFEA3E2-2AC7-4E57-AC88-FE9A3A722F51}.rpt:
The table could not be found.
   at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext)
   at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)
   --- End of inner exception stack trace ---
   at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e)
   at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)
   at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext)
   at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext)
   at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export()
   at CrystalDecisions.CrystalReports.Engine.ReportDocument.Export()
   at ?.?()
when the application crashes VS logs the following in the output screen:
Exception thrown at 0x5D6ABCCF (clr.dll) in IlineSQLEngine.exe: 0xC0000005: Access violation reading location 0x00000000.
The Common Language Runtime cannot stop at this exception. Common causes include: incorrect COM interop marshalling and memory corruption. To investigate further use native-only debugging.
An unhandled exception of type 'System.ExecutionEngineException' occurred in Unknown Module.
Each time I am executing the same code with the same data so I dont know why it does not work?
Essentially the logic of my code seems good but something is going on to cause it to crash as a result of subsequent attemps to export.
I've spent a few days on this and I am badly stuck so any help would be appreciated.


p.s. I already logged this question but after doing a thorough search could not find the original question (no link to it in my account either) - sorry if it turns up twice.

p.p.s. Sorry for formatting - I cant seem to correct the formatting without creating a new question. If its too difficult to read let me know and I'll delete and recreate the question.