Changing connection string at runtime in Enterprise Library

Is there a way to change the connection string of a DataBase object in Enterprise Library at runtime? I've found this link but its a little bit outdated (2005)

I've also found this but it seems to apply to .Net in general, I was wondering if there was something that could be done specifically for EntLib.

I was just passing the connection string name to the CreateDatabase() method in DatabaseFactory object and that worked til yesterday that my project manager asked me to support more than one database instance. It happens that we have to have one database per state (one for CA, one for FL, etc...) so my software needs to cycle through all databases and do something with data but it will use the same config file.

Thanks in advance.

Answers


If you take a look at "Enterprise Library Docs - Adding Application Code" it says this:

"If you know the connection string for the database you want to create, you can bypass the application's configuration information and use a constructor to directly create the Database object. Because the Database class is an abstract base class, you must construct one of its derived types. The derived Database type determines the ADO.NET data provider. For example, the SqlDatabase class uses the SqlClientFactory provider, the SqlCeDatabase class uses the SqlCeProviderFactory provider, and the OracleDatabase class uses the OracleClientFactory provider. It is your responsibility to construct the appropriate type of Database class for the connection string."

It then goes on to give some examples. This would suggest that you should not be using the DatabaseFactory and you should be creating a new Database class for each of your different connections.


look at this:Open Microsoft.practices.EnterpriseLibrary database with just a connection string

just use this follow code, you can programming create database at runtime

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

It's solved my problem. I have a single web app using many database, according to the different subdomain in the url to connect to the different database. such as:

  • abc.test.com ------>using the Db_projectABC
  • def.test.com ------>using the db_ProjectDEF

I use url-rewrite to parse the subdomain name, and use the subdomain name to chose it's database connection string which stored in the main database.

Thanks


Need Your Help

Python - Trying to get a different timezone

python timezone

Totally new to python, I'm actually working on an ex-colleague's script. in looking at it it seems fairly straight-forward. Here's the situation:

open a file whose name and directory are determined by the content selected in combobox vb.net

vb.net string combobox

I have a combobox (combobox1) with a list of names for example: CHARLY SUSAN BOB.

Search a mssql db through android

php android sql-server database json

I have a android application, that in theory, would use php as a proxy and search a mssql db for a set of variables(i.e. start date, end date, and username). I know how I would do it in theory. and...