Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
358 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...