cancel
Showing results for 
Search instead for 
Did you mean: 

Database name is not being changed

Former Member
0 Kudos

I am trying to make changes to the report that is in production by making a copy and connecting to development database. When i try to set the database login info dynamically using vb.net the report still connects to the production.


Dim cr As New crptInvoice()

        Dim crtableLogoninfos As New TableLogOnInfos

        Dim crtableLogoninfo As New TableLogOnInfo

        Dim crConnectionInfo As New ConnectionInfo

        Dim crTables As Tables

        Dim crTable As Table

        'Get database connection info

        With crConnectionInfo

            .ServerName = My.Settings.DevConnectionString.Split(";")(0).Split("=")(1)

            .DatabaseName = My.Settings.DevConnectionString.Split(";")(1).Split("=")(1)

            .UserID = My.Settings.DevConnectionString.Split(";")(3).Split("=")(1)

            .Password = My.Settings.DevConnectionString.Split(";")(4).Split("=")(1)

        End With

        'Set database connection for all tables in report

        crTables = cr.Database.Tables

        For Each crTable In crTables

            crtableLogoninfo = crTable.LogOnInfo

            crtableLogoninfo.ConnectionInfo = crConnectionInfo

            crTable.ApplyLogOnInfo(crtableLogoninfo)

        Next

        ' Loop through each section and find report objects 

        Dim crReportobjects As ReportObjects, crSubReportobject As SubreportObject, subReportDocument As ReportDocument

        Dim crDatabase As Database

        Dim crSections As Sections = cr.ReportDefinition.Sections

        For Each crSection As Section In crSections

            crReportobjects = crSection.ReportObjects

            For Each crReportobject As ReportObject In crReportobjects

                If crReportobject.Kind = ReportObjectKind.SubreportObject Then

                    ' If a subreport is found cast as subreportobject                       

                    crSubReportobject = CType(crReportobject, SubreportObject)

                    ' Open the sub report                       

                    subReportDocument = crSubReportobject.OpenSubreport(crSubReportobject.SubreportName)

                    crDatabase = subReportDocument.Database

                    crTables = crDatabase.Tables

                    ' Loop through each table in the sub report and set the connection info                       

                    For Each crTable In crTables

                        crtableLogoninfo = crTable.LogOnInfo

                        crtableLogoninfo.ConnectionInfo = crConnectionInfo

                        crTable.ApplyLogOnInfo(crtableLogoninfo)

                    Next

                End If

            Next

        Next

The report still connects to ProdDB rather than DevDB. What am i doing wrong? This used to work with VS2008 and after the upgrade to VS2012. Its not working.

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

Change this code:

For Each crTable In crTables 

      crtableLogoninfo = crTable.LogOnInfo 

      crtableLogoninfo.ConnectionInfo = crConnectionInfo 

      crTable.ApplyLogOnInfo(crtableLogoninfo) 

Next 

to:

For Each crTable In crTables

       With crConnectioninfo

               .ServerName = ServerName

               .DatabaseName = DatabaseName

               .UserID = UserID

               .Password = Password

        End With

        crTableLogOnInfo = crTable.LogOnInfo

        crTableLogOnInfo.ConnectionInfo = crConnectioninfo

       crTable.ApplyLogOnInfo(crTableLogOnInfo)

Next

Also, perhaps add .refresh to your code.

Maybe the sample app vbnet_win_subreport_logon.zip will be good to have a look at:

Crystal Reports for .NET SDK Samples - Business Intelligence (BusinessObjects) - SCN Wiki

- Ludek

  Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow us on Twitter

Answers (0)