Home > c#, Oracle, Visual Studio 2005 > Embedded Connection Strings for Enterprise Library 3.0

Embedded Connection Strings for Enterprise Library 3.0

May 6, 2007

Reliance on app.config and web.config for standardized databases in our organization is a bit of a headache.  I realize the “cool” factor, but it simply requires me to go change a dozen+ web.config files when we change the authentication or database server.  Ehh.  If I’m rolling a central framework; I want it to be centralized. Now, my boggle was that the CreateDatabase method didn’t take a connection string and GenericDatabase (to manually build a provider), seemed a bit harried at best.  I mean, where’s the Oracle support? Well, apparently it’s under my nose; I’m just not quick enough to spend some quality time with the Object Browser. Behold!  Microsoft.Practices.EnterpriseLibrary.Data.Oracle!

Database db = DatabaseFactory.CreateDatabase(“Config_Setting”);


OracleDatabase db = new OracleDatabase(“connectionstring”);

Now, repeating the horrid TNS connection string is a hassle, so how can we make it a bit more user friendly?  Create a simple class that acts, sorta, like an enumerator.

static class ConnectionStrings {   
internal static string SIS   

Now, we can replace our “connectionstring” with:

OracleDatabase db = new OracleDatabase(ConnectionStrings.SIS);

When the database information changes, we simply update our SIS (or whatever database) string and push out the shared DLL to our web server.  You can do this for any database type, given you are using the correct Enterprise Library class (OracleDatabase vs. SqlDatabase).  Before you make these sweeping changes; however, be considerate of your enterprise and how your libraries will be used.  If you are storing user accounts or database information that is very sacred to your environment—these .dll’s can easily be relfected out—your information is NOT secure.  For those times, I don’t know much better of a solution than an encrypted .config file.

Tags: , ,

Categories: c#, Oracle, Visual Studio 2005
  1. June 7, 2007 at 2:38 pm

    Nice little snippet, worked great for me!

  1. No trackbacks yet.
Comments are closed.
%d bloggers like this: