Generic Database requirment

N

Nicol

Hi,
My requirement is to use any Databse in my application as configurable.
Now I decided to use Enterprise library 4.0 to support all databases by
using common classe such as DBcommand, IDAtareader etc., have seen
enterprise library, by itself reads Database connections from confg file.. I
have requirement to add additional requiremnet to pass connection strings
from my code to Enterprise library to handle. i.e. If no connection string is
mentioned in the code, it should read from config file. How to specify
connection string via code.. The one i used is

Database db = DatabaseFactory.CreateDatabase("Test");

string sqlCommand = "Select * " +
"From audit";
DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);
using (IDataReader dataReader = db.ExecuteReader(dbCommand))
{
}

Where to specify connection string here?

Thanks in advance
Nithiya
 
J

Jeff Winn

Sorry, been busy at work the past few days and getting home late (worked
about 13 hours today, yipee).

Anywho, the Enterprise Library must have the connection string stored in the
configuration file, there is no way to get around that. Reason being the
data block also needs to know what kind of database it's using (that's what
the provider element is for) and not just the connection string. Once the
configuration file has been read, it is stored in memory for the lifetime of
the appdomain that loaded it.

What I have done in the past was remote all the calls to the data layer in a
seperate appdomain that I could reload when the configuration needed to
change. It's not easy, and ill advised. I probably wouldn't do it again if i
didn't have to, but that's the only way I was able to make the configuration
dynamic.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top