VB.NET, Crystal Reports. This property is currently in a read-only state and cannot be modified.


I am running a Crystal Reports export to XML and am running into an issue.  I am using the COM object.  I get the error:  "This property is currently in a read-only state and cannot be modified." when I run my app sometimes.  It ishard to reproduce and the only way I can tell this is set off is by certain dates in my LASTRUN variable.  Sometimes dates will work and others won't.  The confusing thing is that index 0-4 will work fine and then when it gets to 5 it will error out.  Although other times, none of them will work.  I don't know and am very confused.



Here is the code:
2004,11,12,00,00,00 as lastrun
5 as index
DataDump_Property as arr

    Private Function Get_Data(ByVal arr As String, ByVal index As Integer, ByVal lastrun As String) As Boolean
        On Error GoTo Error_code
        Dim rpt As CRAXDRT.Report
        Dim rpt_nd As MSXML2.IXMLDOMNode
        Dim filter_nd As MSXML2.IXMLDOMNode
        Dim cr As CRAXDRT.Application
        Dim userid, pwd As Object

        'new application
        cr = New CRAXDRT.Application()
        'crystal login info
        userid = "_____________"
        pwd = "_____________"

        'open specified report
        rpt = cr.OpenReport("c:\" & arr & ".rpt")
        'only log in at application level if it is the first file, else max simultaneous users error
        rpt.Database.Tables(1).ConnectBufferString = "Provider=MSDAORA;;Data Source=_____;;User ID=" & userid & ";;Password=" & pwd & ";;Locale Identifier=1033;;OLE DB Services=-5"

        '5/6/2003 12:00:00AM ---> DateTime(Y,M,D,H,M,S)
        'sets filter to the get all updates and inrts from last run date
        If index = 3 Or index = 0 Then
            rpt.RecordSelectionFormula = "{Command.UPDATE_DATE} >= DateTime(" & lastrun & ") OR {Command.INSERT_DATE} >= DateTime(" & lastrun & ")"
        End If
        '***end filter section

        'export xml from crystal
        rpt.ExportOptions.DestinationType = CRAXDRT.CRExportDestinationType.crEDTDiskFile
        rpt.ExportOptions.FormatType = CRAXDRT.CRExportFormatType.crEFTXML
        rpt.ExportOptions.XMLFileName = "c:\xml\" & arr & ".xml"
        rpt = Nothing
        cr = Nothing
        Exit Function
        logger.WriteLine("Get\Error @ " & Now() & ": " & Err.Number & vbTab & Err.Source & vbTab & Err.Description, EventLogEntryType.Error)
        Resume Exit_code
    End Function
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What ver of CR are you running?
cmgtechAuthor Commented:
CR 9.  The problem only seems to happen for certain dates but that is only a guess... pretty new to this and I have lost a lot of sleep over this without being able to find any acceptable workaround or even an explaination or reason of this error.

Here is some of my error log:

Start: 11/30/2004 2:58:20 AM
For Dates: 2004,11,29,00,00,00
DataDump_L: 11/30/2004 2:59:16 AM
DataDump_R: 11/30/2004 2:59:23 AM
Get\Error @ 11/30/2004 2:59:26 AM: -2147417851      Interop.CRAXDRT      The server threw an exception.
DataDump_L: 11/30/2004 2:59:27 AM
DataDump_Lo: 11/30/2004 2:59:34 AM
Get\Error @ 11/30/2004 2:59:35 AM: -2147184634            This property is currently in a read-only state and cannot be modified.
DataDump_Loa: 11/30/2004 2:59:37 AM
Get\Error @ 11/30/2004 2:59:40 AM: -2147184634            This property is currently in a read-only state and cannot be modified.
DataDump_Pr: 11/30/2004 2:59:41 AM
Get\Error @ 11/30/2004 2:59:42 AM: -2147184634            This property is currently in a read-only state and cannot be modified.
DataDump_Pre: 11/30/2004 2:59:42 AM
DataDump_R(merge): 11/30/2004 2:59:45 AM
DataDump_Loa (merge): 11/30/2004 2:59:54 AM
DataDump_Lo (merge): 11/30/2004 3:01:18 AM
DataDump_L (merge): 11/30/2004 3:02:20 AM
DataDump_Pr (merge): 11/30/2004 3:02:34 AM
DataDump_P (merge): 11/30/2004 3:02:39 AM
Remove Nodes: 11/30/2004 3:02:44 AM
Passing to Update Page: 11/30/2004 3:02:44 AM
File Loaded, Posted.
Done Processing @ 11/30/2004 3:04:43 AM
Well first of all I would not use the CRAXDRT object.
Here is some code that I use with cr9...


You can use a ADO or SQL connection...

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.Shared
Imports ADODB                                 '<---- Access
Imports System.Data.SqlClient            '<---- SQL

    Public myReport As New ReportDocument        'Gobal Report Doc
    Public sAppPath = Application.StartupPath        'Application Directory Main Path
    Public sReportPath = "\Reports\"                     'Reports Directory Path

   '**** Server Connection Vars *********
    Public sDBServer As String = "MYSERVER"
    Public sUSERid As String = "MYUSER"
    Public sDBName As String = "MYDATABASE"
    Public sDBPass As String = ""
    Public Con As OleDb.OleDbConnection      '<--- for Access
    Public Connect As SqlConnection             '<--- for msSQL
    Public sSQL As String

    Private Sub GetReportConnection(ByVal myReport)
        ' Objects used to set the proper database connection information
        Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
        Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo

            ' Load the report
            myReport.Load(sAppPath & sReportPath & sReportName, CrystalDecisions.[Shared].OpenReportMethod.OpenReportByTempCopy)
            ' Set the connection information for all the tables used in the report
            For Each tbCurrent In myReport.Database.Tables
                tliCurrent = tbCurrent.LogOnInfo
                With tliCurrent.ConnectionInfo
                    .ServerName = sDBServer
                    .UserID = sUSERid
                    .Password = ""
                    .DatabaseName = sDBName
                End With
            Next tbCurrent
        Catch Exp As LoadSaveReportException
            MsgBox("Incorrect path for loading report.", _
                    MsgBoxStyle.Critical, "Load Report Error")
        Catch Exp As Exception
            MsgBox(Exp.Message & "   in GetReportConnection Procedure", MsgBoxStyle.Critical, "General Error")
        End Try
    End Sub


  Private Sub ExptReport(ByVal myReport)
       Dim myExportOptions As New CrystalDecisions.Shared.ExportOptions
       Dim myDiskFileDesOptions As New CrystalDecisions.Shared.DiskFileDestinationOptions

                          myDiskFileDesOptions.DiskFileName = sAppPath & sReportPath &  "MYXMLFILE.html"
                            myExportOptions = myReport.ExportOptions
                            Dim myFormatTypOpt As New CrystalDecisions.Shared.HTMLFormatOptions
                            With myFormatTypOpt
                                .HTMLBaseFolderName = sReportPath
                                .HTMLFileName = myDiskFileDesOptions.DiskFileName
                                .HTMLEnableSeparatedPages = True
                                .HTMLHasPageNavigator = True
                            End With
                            With myExportOptions
                                .ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
                                .ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.HTML40
                                .DestinationOptions = myDiskFileDesOptions
                                .FormatOptions = myFormatTypOpt
                            End With
                Catch Exp As ExportException
                    MsgBox("Incorrect path for saving report.", _
                            MsgBoxStyle.Critical, "Load Report Error")
                Catch Exp As System.Reflection.TargetInvocationException
                    'Jump over this error
                Catch Exp As Exception
                    MsgBox(Exp.Message & " in CheckReportList", MsgBoxStyle.Critical, "General Error")
                End Try
            End If
      End Sub

'SAMPLE for PASSING Parameters

  Private Sub Parmas(ByVal myReport) 'FOR Dates and Ranges
        ' Objects used to set the parameters in the report
        Dim pvCollection As New ParameterValues
        Dim pdvID As New ParameterDiscreteValue
        Dim pdvStartName As New ParameterDiscreteValue
        Dim pdvEndName As New ParameterDiscreteValue
        Dim pdvPageCount As New ParameterDiscreteValue
                '********************************* ID **********************************
                ' Set the discreet value to the Start Date.
                pdvID.Value = sdbID
                ' Add it to the parameter collection.
                ' Apply the current parameter values.

                '********************************* Start Date **********************************
                pdvStartName.Value = sDBStartDate
                myReport.DataDefinition.ParameterFields("Start Date").ApplyCurrentValues(pvCollection)

                '********************************* End Date **********************************
                pdvEndName.Value = sDBEndDate
                myReport.DataDefinition.ParameterFields("End Date").ApplyCurrentValues(pvCollection)
                '********************************* Page Count **********************************
                pdvPageCount.Value = iPageCount + 1
                myReport.DataDefinition.ParameterFields("Page Count").ApplyCurrentValues(pvCollection)
         Catch Exp As ParameterFieldException
            MsgBox("Incorrect Parameter Field." & vbNewLine & "In Parmas Procedure Code", _
                    MsgBoxStyle.Critical, "Load Report Error")
        Catch Exp As InvalidArgumentException
            MsgBox(Exp.Message & vbNewLine & "In Parmas Procedure Code", MsgBoxStyle.Critical, "General Error")
        Catch Exp As Exception
            MsgBox(Exp.Message & vbNewLine & "In Parmas Procedure Code", MsgBoxStyle.Critical, "General Error")
        End Try
    End Sub

'This may not what you are looking for, but I think the  new .NET code will help you.
Then using Interop. object.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cmgtechAuthor Commented:
Thanks, I'll try it out later today and get back to you hopefully by tomorrow... a little busy lately.


cmgtechAuthor Commented:
tried it out and i connect and can export to pdf fine with no errors.  the thing is, I dont know when this is going to crash out.  also I now have to export it to XML and con't find anything about how to do it anywhere.  with the CRAXDRT, I can just change portabledocumentformat to xml and it is fine.  no idea how to do it here and really con't find anyhting on how to do it.  

Thanks a lot, you really got me at least on the right track.

I am going to start a new thread that may help people find it easier.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.