0

I am using the Microsoft.Practices.EnterpriseLibrary Database tools and I'm having trouble creating a new database using just the connection string information.

Ideally I would like to do the following:

Database dbEngine = DatabaseFactory.CreateDatabase( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\data\test1.mdb;Persist Security Info=True");
Is it possible to create a database using just the connection string?

If so, how can it be achieved? I have seen a similar question for SqlDatabase here: Open Microsoft.practices.EnterpriseLibrary database with just a connection string

Community
  • 1
  • 1
Satya
  • 1

1 Answers1

0

I believe the Factory .. keys off of

providerName="System.Data.SqlClient"

(which is a part of the ConnectionString(s) information in the config file.

to know which Concrete object to use.

Therefore, you cannot use (only) the connection string to create the database. Because it has nothing to "key" off of to make the decision on which concrete (subclass that extends Database class)......

Thus the other answer is the best you can do.

Database mydb = new EnterpriseLibrary.Data.Sql.SqlDatabase("connection string here");

You manually pick the concrete(subclass). (Which is being done on the right side of the "=" sign....this line is hard-picking the SqlDatabase as the concrete.

granadaCoder
  • 26,328
  • 10
  • 113
  • 146