Bon Perez
Bon Perez

Reputation: 55

dynamic connection string using enterprise library 5

May I ask if you have a sample code snippet that I can start with in working with Enterprise Library 5 application block? The requirement is for me to dynamically change connection string at runtime. The connection string will not come from config file, instead from a sql server database. The sql server database will then have a table containing the list of connection strings to different databases that will be maintained by a group of admins. Initially, this table of connection strings will contain connections to a DB2 and SQL Server Database.

I checked this link:changing conn string at runtime

bu I can't make it work. Is there a simple way in doing this in Enterprise library?

Thank you.

Upvotes: 1

Views: 2609

Answers (1)

Rocklan
Rocklan

Reputation: 8130

Connect to your first DB, pull out the list of connection strings and then connect to the other DB like so:

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

Upvotes: 3

Related Questions