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.
精彩评论