如何在 vb.net 中使用 OLE DB 更改 Crystal Reports 连接字符串?

发布于 2025-01-03 20:20:21 字数 332 浏览 3 评论 0原文

我有一个“Connection.vb”,其中存储了我的所有连接字符串并由整个程序使用。

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

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

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

提前感谢..

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

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..

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...

thanks in advance..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半透明的墙 2025-01-10 20:20:21

我刚刚花了一些时间在 VB 中解决这个确切的问题。我希望这有帮助。

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

   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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文