How to change Crystal Reports connection string using OLE DB in vb.net?

◇◆丶佛笑我妖孽 提交于 2019-12-01 22:50:55

I just spent some quality time figuring out this exact problem, in VB. I hope this helps.

Replace YourDataContext() with whatever your data context is. Alternatively, you can get the connection string from the AppConfig as usual. I am getting mine from the data context because we are migrating databases and keep changing the connection strings.

   Private Sub SetCrystalReportsConnection(ByRef report As ReportDocument)

    Dim sqlConnInfo As SqlConnectionStringBuilder = New SqlConnectionStringBuilder(New YourDataContext().Connection.ConnectionString)

    For Each connection As InternalConnectionInfo In report.DataSourceConnections
        If sqlConnInfo.IntegratedSecurity Then
            connection.SetConnection(sqlConnInfo.DataSource, sqlConnInfo.InitialCatalog, True)
        Else
            connection.SetConnection(sqlConnInfo.DataSource, sqlConnInfo.InitialCatalog, sqlConnInfo.UserID, sqlConnInfo.Password)
            connection.IntegratedSecurity = False
        End If
    Next

End Sub
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!