CreateDatabase method in entlib 3

Topics: Data Access Application Block
Feb 5, 2007 at 10:16 PM
Does the CreateDatabase method in version alter the behavior of the overload that accepts a string value? What i would really like is if that one would create the default connection if the supplied value is "" (string.Empty).

I don't want to create code like:

if (String.IsNullOrEmpty(connectionName))
db = DatabaseFactory.CreateDatabase();
db = DatabaseFactory.CreateDatabase(connectionName);

or any similar construct.
Feb 5, 2007 at 11:10 PM
The overload that takes a string expects a named Connection String. As you probably experienced, if you pass an empty string you will get an exception: "The value can not be null or string or empty." If you take a peek at the source code you will see the parameter validation.

It is expected that if you just want to connect to the default database, you would use the overload that does not accept a named connection string.




David Hayden
Microsoft MVP C#