Is there a way to change the connection string of a DataBase object in Enterprise Library at runtime? I\'ve found this link but its a little bit outdated (2005)
I\'v
We can use the following code snippet to connect to multiple databases.
DLLs to Add as Reference
The snippet:
var builder = new ConfigurationSourceBuilder();
builder.ConfigureData()
.ForDatabaseNamed("LocalSqlServer1")
.ThatIs.ASqlDatabase()
.WithConnectionString(@"Data Source=PCNAME\SQLEXPRESS;Initial Catalog=ContactDB;Integrated Security=True")
.ForDatabaseNamed("LocalSqlServer2")
.ThatIs.ASqlDatabase()
.WithConnectionString(@"Data Source=PCNAME\SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=True");
var configSource = new DictionaryConfigurationSource();
builder.UpdateConfigurationWithReplace(configSource);
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
Database destinationDatabase = DatabaseFactory.CreateDatabase("LocalSqlServer2");