Can I programmatically change a crystal report with datasource ODBC (RDO) to OLE DB (ADO)?

Posted on 2014-08-18
Last Modified: 2015-02-08
My question is kind of like this pretty much unanswered one on stack overflow:

I have about 400 reports that needed to have their datasource changed. Fortunately, I had a little program that did the bulk of them. But I wanted to change them all to ole db (ado), and those that were originally odbc rdo changed the server, database, and username, but didn't change the connection type from rdo to ado. Or,if it did, it didn't save the report.  So is this possible to do programmatically? My code is below: Using crystal version xi release 2,

        'create a reportdocument and load a reportfilename into it; the filenames are in a listbox 
        'populated(from) 'reportsOriginal' folder.
        'When done, Copy (using saveas method) to 'reportsFinished' folder.
        'But how do we Programmatically change the datasource from ODBC (RDO) to OLE DB (ADO)?
        'We Can determine if it is RDO, but cannot figure out how to change it.
        Dim ciReportConnection As New ConnectionInfo
        Dim rptServerName = ""
        Dim fname As String = ""
        Dim OutPutDir As String = ""
        Dim knt As Integer = 0
        Const cstAdo As String = "OLE DB (ADO)"
        'populate using controls on the form
        With ciReportConnection
            'First attempt to change the report to ADO
            'This causes no error in the report but doesn't work
             .AllowCustomConnection = True
            'First Attempt
            'If the report was  RDO, this causes the report to have no datasource. but causes no error if the report was ADO anyway.
            ''.Attributes.Collection.Add(New NameValuePair2("QE_DatabaseType", cstAdo))
            'second attempt-worthless too
            '.LogonProperties.Add(New NameValuePair2("QE_DatabaseType", cstAdo))
            .Type = ConnectionInfoType.CRQE
            .ServerName = cboServer.Text
            .DatabaseName = txtDatabase.Text
            .UserID = txtuserId.Text
            'note The only way to save a password in a report anyway is to use an odbc connection with a saved password.
            ' But just for fun include password. It is best to use integrated security if possible.
            .Password = txtPassword.Text
            .IntegratedSecurity = chkIntegrated.Checked
            End With
            For Each item As String In lstReports.SelectedItems
                Dim str() As String
                str = Split(item, "\")
                fname = str(UBound(str))

                Dim crReportDocument As New ReportDocument
                'another attempt to set everything to ADO
                ciReportConnection.LogonProperties.Add(New NameValuePair2("QE_DatabaseType", "OLE DB (ADO)"))
                If crReportDocument.DataSourceConnections.Count > 0 Then
                    rptServerName = crReportDocument.DataSourceConnections(0).ServerName
                    'this at least alerts us if the report is RDO
                    MessageBox.Show(GetRdoReportName(crReportDocument, fname))
                End If

                rptServerName = UCase(rptServerName)
                lblReportCopy.Text = "Currently Working on " & fname
                'Assign data source details to tables if original file servername doesn't match the desired value
                If rptServerName <> "" And rptServerName <> UCase(cboServer.Text) Then
                    ' (copied from stackoverflow) The meat of the program is right here; this is what changes the logon info
                    For Each table As Table In crReportDocument.Database.Tables
                        table.LogOnInfo.ConnectionInfo = ciReportConnection
                    For Each subrep As ReportDocument In crReportDocument.Subreports
                        For Each table As Table In subrep.Database.Tables
                            table.LogOnInfo.ConnectionInfo = ciReportConnection
                End If

                'This shows a logon error for any originally (and unchanged) RDO report, but no error for an originally ADO report.
                OutPutDir = Application.StartupPath + "\ReportsFinished\"
                'all 'ADO' changes seem to be lost when saved. Maybe they work when using a crystal viewer
                crReportDocument.SaveAs(OutPutDir + fname)
                knt += 1
        Catch ex As Exception
        End Try
        MessageBox.Show(knt & " New files created in " & OutPutDir)
    End Sub
    Private Function GetRdoReportName(ByRef CrReportDocument As ReportDocument, ByVal fname As String) As String
        Const cstAdo As String = "OLE DB (ADO)"
        Dim test As ArrayList = CrReportDocument.DataSourceConnections(0).Attributes.Collection
        Dim i As Integer
        Dim Substr As String
        For i = 0 To test.Count - 1
            If UCase(test(i).name) = "QE_DATABASETYPE" Then
                Substr = (test(i).value)
                If InStr(UCase(Substr), "RDO") > 0 Then
                    'Third attempt to change the report to ADO
                    'code below causes no error but does not change the report to ado..
                    test(i).value = cstado
                    Return fname
                End If
            End If
        Return ""
    End Function

Open in new window

Question by:OutOnALimbAlways
    LVL 100

    Accepted Solution

    According to this question from the SAP knowledge base you have to use the  InProc RAS SDK.

    They also recommend looking at a blog on the same subject
    When to use the 'Replace Connection' method using the Crystal Reports or InProc RAS SDK for .NET

    Another article worth reading is the white paper from SAP on Troubleshooting Database Connection Problems


    Author Comment

    Thanks mlm, at least that gives me a start.  Fortunately it's not critical [yet] so I do have some time to play around with it.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Suggested Solutions

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    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…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    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…

    732 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

    20 Experts available now in Live!

    Get 1:1 Help Now