如何在 vb.net 中使用 OLE DB 更改 Crystal Reports 连接字符串? [英] How to change Crystal Reports connection string using OLE DB in vb.net?

查看:24
本文介绍了如何在 vb.net 中使用 OLE DB 更改 Crystal Reports 连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Connection.vb",我的所有连接字符串都在其中存储并供整个程序使用.

i have a "Connection.vb" where all my Connection string stored and used by the entire program.

我是 Crystal Reports 的新手.. 我想根据我创建的连接字符串更改其连接字符串...我使用 MS SQL 2008.. SQL Server Native Client 10.0 OLE DB Provider..

i'm new to Crystal Reports.. and i want to changes its connection string based on the connection string i made... im using MS SQL 2008.. SQL Server Native Client 10.0 OLE DB Provider..

这是我的连接字符串."Provider=SQLNCLI10;Server=....SQLEXPRESS;Database=Blah;Trusted_Connection=yes"

and here is my connection string. "Provider=SQLNCLI10;Server=....SQLEXPRESS;Database=Blah;Trusted_Connection=yes"

我试图用谷歌搜索它..但他们使用不同的语言、不同的数据库和复杂的示例......

i tried to google it.. but they are using different language, different database, and complex examples...

提前谢谢..

推荐答案

我刚刚花了一些时间在 VB 中找出这个确切的问题.我希望这会有所帮助.

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

将 YourDataContext() 替换为您的数据上下文.或者,您可以照常从 AppConfig 获取连接字符串.我是从数据上下文中获取我的,因为我们正在迁移数据库并不断更改连接字符串.

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

这篇关于如何在 vb.net 中使用 OLE DB 更改 Crystal Reports 连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆