开发者

using a connection string in web.config for crystal report

开发者 https://www.devze.com 2022-12-29 23:39 出处:网络
I`m having problems between two开发者_如何学Go servers, wich use differente odbc dsn. My apps work great but crystal reports uses the original odbc connection, how can I fix this?

I`m having problems between two开发者_如何学Go servers, wich use differente odbc dsn.

My apps work great but crystal reports uses the original odbc connection, how can I fix this?

I'm thinking of using the same connection string in the web.config, but I don't know how.

found this but is too confusing for me

thanks,


You can't use a connection string in the same way you can with an ado.net connection. However, you can certainly use values from the web.config to specify the connection info. Create an instance of the ConnectionInfo class and set the ServerName, DatabaseName, UserID, and Password properties. Then attach it to each of the tables in the report:

ConnectionInfo reportConnectionInfo = new ConnectionInfo();
reportConnectionInfo.ServerName = ConfigurationManager.AppSetting["ServerName"];
reportConnectionInfo.DatabaseName = ...;
reportConnectionInfo.UserID = ...;
reportConnectionInfo.Password = ...;

foreach (Table table in reportDocument.Database.Tables) {
  table.LogOnInfo.ConnectionInfo = reportConnectionInfo;
}

If you try to use this suggestion, beware of my sloppy typing...


You can use the connection string. You have to create an instance of the database provider ConnectionStringBuilder passing in the Connection String pulled from a config file. Here is an example in VB.

Dim connString As String = ConfigurationManager.ConnectionStrings["MyDbConn"].ConnectionString
Dim connStringBuilder As SqlConnectionStringBuilder = New SqlConnectionStringBuilder(connString)

Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
myConnectionInfo.DatabaseName = connectionStringBuilder.InitialCatalog
myConnectionInfo.UserID = connectionStringBuilder.UserID
myConnectionInfo.Password = connectionStringBuilder.Password
myConnectionInfo.ServerName = connectionStringBuilder.DataSource
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号