How do I change a Crystal Report's ODBC database connection at runtime?

前端 未结 6 2056
暗喜
暗喜 2020-11-30 10:35

I have a report made with Crystal Reports 2008 that I need to deploy a production system which means that I need to be able to change the database connection at runtime. Th

6条回答
  •  死守一世寂寞
    2020-11-30 10:56

    I just went through this same ordeal.

    I set my connections like this (where sDataSource etc... are string with the information)

        Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
        myConnectionInfo.ServerName = sDataSource
        myConnectionInfo.DatabaseName = sInitialCatalog
        myConnectionInfo.UserID = sUserID
        myConnectionInfo.Password = sPassword
    
        Dim myTables As Tables = report.Database.Tables
        Dim myTableLogonInfo As TableLogOnInfo = New TableLogOnInfo()
        myTableLogonInfo.ConnectionInfo = myConnectionInfo
        For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables
            myTable.ApplyLogOnInfo(myTableLogonInfo)
    
            myTable.LogOnInfo.ConnectionInfo.DatabaseName = myTableLogonInfo.ConnectionInfo.DatabaseName
            myTable.LogOnInfo.ConnectionInfo.ServerName = myTableLogonInfo.ConnectionInfo.ServerName
            myTable.LogOnInfo.ConnectionInfo.UserID = myTableLogonInfo.ConnectionInfo.UserID
            myTable.LogOnInfo.ConnectionInfo.Password = myTableLogonInfo.ConnectionInfo.Password
    
        Next
    

提交回复
热议问题