none
Options for switching multiple class libraries' data locations? RRS feed

  • Question

  • This is a question that's still confusing me.
    What's the best... well, bad word.  What I mean is what would be the way to make the change most centralized and/or

    what are the advantages of different options?

     

    Example:

     

    Customer class library

    Products class library

    Employee class library

     

    how would these classes best be designed so all objects could have their data sources (connection strings, really) switched all at once without targeting each object?

     

    My ideas so far are:

     

    Have a SqlConnection with the target connection string passed into the constructor of each and every class.  The disadvantage is that every damn library object has to have this passed to it Sad

     

    Another idea: Very tempting, but maybe a bad idea, :  have each class library look for an app or web config file, and then determine which server to hit.  This way, you'd only be setting the string once.

     

    Have each class library point to another dll which determines the connection string, and if you are testing, change that base dll to point to different servers.  This is probably my favorite so far.

     

    Another issue is that some classes need to hit 2 different types of data sources that arealways on 2 different servers, so that makes things even more complex because a person would need to have a way to switch both of them.

    Wednesday, January 23, 2008 10:52 PM

Answers

  • I would create database factory class in separate DLL and all applications would make all database-related calls using that DLL. In this case your will have central place for all database related calls. That factory would also read connection string from application's configuration file, so your do not need to pass it from any place in application.

     

    Thursday, January 24, 2008 11:27 AM
    Moderator