<< back to blog

.NET Config for Multiple Developers

Apr 30, 2009, .net ~ nhibernate

Here's a simple solution I just thought up for when you have multiple developers working on a project, and you want each to have their own connection string in Web.config (under source control).

I've seen some pretty complex approaches to this, but what about this one...

//Global.asax.cs

protected void Application_Start()
{   
    //other stuff here...

    UoW.Configure(
        WebConfigurationManager
           .ConnectionStrings[Environment.MachineName].ConnectionString);
}

Then, in web config, you'd have something like this.

//Web.config

<connectionStrings>     
    <add name="TOBIN-AB69C7A1F" connectionString="server=.\SQLEXPRESS2008;database=MdlDevelopment;Trusted_Connection=true"/>
    <add name="LIVESERVER-101" connectionString="data source=192.168.1.87;Integrated Security=SSPI;Trusted_Connection=true"/>
    <!-- add yours here -->

In short, each developer adds a new connection string to the Web.Config. The name is his machine name. Simple huh!

You may also like...

blog comments powered by Disqus