Skip to Content
0
Former Member
Dec 12, 2013 at 08:21 PM

Database name is not being changed

32 Views

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.