如何在vb.net中使用OLE DB更改Crystal Reports连接字符串? [英] How to change Crystal Reports connection string using OLE DB in vb.net?
问题描述
我有一个Connection.vb,其中所有的连接字符串存储和使用的整个程序。
i have a "Connection.vb" where all my Connection string stored and used by the entire program.
我是水晶报表希望根据连接字符串更改其连接字符串我使用MS SQL 2008 .. SQL Server Native Client 10.0 OLE DB提供程序..
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"
我试图google。他们使用不同的语言,不同的数据库和复杂的例子...
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屋!