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

Posted on 2004-11-29
Last Modified: 2007-12-19

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
Question by:cmgtech
    LVL 27

    Expert Comment

    What ver of CR are you running?

    Author Comment

    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
    LVL 27

    Accepted Solution

    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.

    Author Comment

    Thanks, I'll try it out later today and get back to you hopefully by tomorrow... a little busy lately.



    Author Comment

    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.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    This video discusses moving either the default database or any database to a new volume.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now