Database connection read from DB

Database connection read from DB

Old forum URL: forums.lhotka.net/forums/t/6808.aspx


drinoh posted on Friday, April 17, 2009

I am trying to create a set of CSLA business objects that use a db connection that is not hard coded, i.e. read from an administrative database (whose connection string will be hard coded).  This will allow me to publish the same code for all customers without having to manually update the dbconnection string for each.

Any thoughts on the best way to accomplish this?

dlambert replied on Friday, April 17, 2009

Are you talking about centralized config management?  Like, you'd push a button on your admin app and it would barf out a bunch of config files, or are you fishing for something that cuts out the config files altogether?

drinoh replied on Friday, April 17, 2009

Thanks for your question / response!

I have a package software product that I publish to a number of different customers.  Each customer has their own database which I house and maintain on our servers (ASP model), so when I publish updates, I have to go in an manually update the business classes to connect to the correct customer database.  Today, I do that by creating a number of 'named' database connections in the config file (using MS Enterprise Library for data access), each with their own connection string and I hard code the named database connection into the business objects.

I want to be able to have the user connect to an 'admin' database and log in there.  From there, it will pull the correct named database string for that customer and use that for all business object datbase connections. 

Since these objects are mobile and running on the database server when data access is done, the only way I see to do this now is to just pass the named database connection to each object during its creation.  That will work but seems awkward to me.  I am wondering if there is a more elegant way this is typically handled.  I assume many others have had to do something similar.

Thanks.

 

dlambert replied on Friday, April 17, 2009

If I understand your comment correctly, I'd consider wrapping the specific implementation in a connection factory and just grab a connection from the factory in the business objects.

Copyright (c) Marimer LLC