开发者

Permanently change database of an OLE DB Connection

开发者 https://www.devze.com 2023-03-03 04:27 出处:网络
I\'m working with an OLE DB Connec开发者_如何学Gotion that has to change databases at runtime. I have found the ChangeDatabse method to be somewhat useful, but as soon as I close the connection it res

I'm working with an OLE DB Connec开发者_如何学Gotion that has to change databases at runtime. I have found the ChangeDatabse method to be somewhat useful, but as soon as I close the connection it resets back to the original value of the connection string.

Since my connection string could be written for a number of servers I would like to avoid changing it directly.

Any ideas?


Why dont you use DbConnectionStringBuilder

System.Data.Common.DbConnectionStringBuilder builder = 
    new System.Data.Common.DbConnectionStringBuilder();
builder["Data Source"] = "(local)";
builder["integrated Security"] = true;
builder["Initial Catalog"] = "AdventureWorks;NewValue=Bad";

So you could change the Initial Catalog like builder["Initial Catalog"] = "whatever";

It contains ConnectionString property as well to get the connection string.

Have a look as MSDN.

0

精彩评论

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