Crystal Reports - Exception - Attempted to Read/Write Protected Memory

CIMStu

Member
Joined
Mar 9, 2010
Messages
13
Programming Experience
Beginner
Hi,

I have resolved my Excel Filetype problem thanks to help from here! :)

Unfortunately i am now getting an unhandled exception error which i can't get my head around.

I am using Crystal Reports 9 Viewer to open a report i have created in Crystal Reports, which uses the data in the Excel document created, and some from another database.

If i run my code, and set my report datasource to a Blank report, it opens fine, if i set it to a report that only references the other database, it loads fine.

As soon as i try to open the report i want, which references my excel spreadsheets, i get a exception "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

My Code is below

VB.NET:
Dim crApp As CRAXDRT.Application
        Dim oForm As New frmCrystal
        Dim mvarFileName As String

        Me.Cursor = Cursors.WaitCursor

        mvarFileName = "C:\Program Files\CIM\Trial_Kitting.rpt"
        crApp = New CRAXDRT.Application
        oReport = crApp.OpenReport(mvarFileName, 1)
        With oReport
            .VerifyOnEveryPrint = False
            .MorePrintEngineErrorMessages = False
            .PrintDate = Now
            '            .PaperOrientation = CRAXDRT.CRPaperOrientation.crLandscape
            .DiscardSavedData()
        End With

        oForm.Text = "Crystal Reports - Multiple Trial Kitting"
        oForm.AxCRViewer91.ReportSource = oReport
        oForm.AxCRViewer91.Zoom(1)
        oForm.AxCRViewer91.ViewReport()

        Me.Cursor = Cursors.Default
        Application.DoEvents()

        oForm.ShowDialog()

        oForm = Nothing
        oReport = Nothing
        crApp = Nothing
        mvarFileName = Nothing

The line that triggers the exception is the Application.DoEvents.
If i remove that line the exception occurs and doesn't indicate which line is throwing the exception.

I have googled the error and read up the help files and alot of information i've read refers to unmanaged com components and cross threading. Something i have heard of but have no understanding of beyond that. D'oh!!

Any help appreciated
 

Latest posts

Back
Top