I am using following code to setup connection string:
ConfigurationSourceBuilder builder = new ConfigurationSourceBuilder ();
builder.ConfigureData ()
.ForDatabaseNamed ( "TestDatabase" )
.ThatIs.ASqlDatabase ()
.WithConnectionString ( "Data Source=127.0.0.1;User Id=sa;Password=123;Initial Catalog=DataAccessExamples;" )
.AsDefault ();
var configSource = new DictionaryConfigurationSource ();
builder.UpdateConfigurationWithReplace ( configSource );
EnterpriseLibraryContainer.Current
= EnterpriseLibraryContainer.CreateDefaultContainer ( configSource );
After executing above code I expect following code to work but it says connection not initialized and command.Connection property always keeps null.
Database database = DatabaseFactory.CreateDatabase ();
DbCommand command = database.GetSqlStringCommand ( "Select * from TT" );
DbDataReader dbReader = command.ExecuteReader ( System.Data.CommandBehavior.CloseConnection );
while (dbReader.Read ())
{
System.Diagnostics.Debug.WriteLine ( dbReader[0].ToString () );
}
Please can anyone tell me why connection is not getting initialized?
I am using above code in a library project and want to configure DAAB at runtime.
Thanks