AFAIK, Its not possible to set the connection string dynamically, however you can write a Custom database factory to create a database with dynamic connection string
public static class CustomDatabaseFactory
{
static readonly DbProviderFactory dbProviderFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");
public static Database CreateDatabase(string connectionString)
{
return new GenericDatabase(connectionString, dbProviderFactory);
}
}
and instead of calling this
Database db = DatabaseFactory.CreateDatabase();
call this method
Database db = CustomDatabaseFactory.CreateDatabase(connstring);
worked well for me!