Script(s)

technology as-is

Handling multiple configuration settings (Development, Staging, Production) gracefully.

| 1 Comment

In Asp.net 2.0 multiple connectionStrings & appSettings can be handled very easily using the attribute “configSource”

create a new xml file devAppSettings.config under a new folder myConfigsettings

<?xml version=”1.0″?>
<appSettings>

  <add key=”uploadfolder” value=”C:\test\UploadDocs”/>

  <add key=”domainname” value=”devdomain”/>

</appSettings>


create a new xml file devconnectionStrings.config under a folder myConfigsettings

<?xml version=”1.0″?>
<connectionStrings>

  <add name=”nwind” connectionString=”Data Source=(localhost);Initial Catalog=nwind;User Id=sa;Password=sa;”
    providerName=”System.Data.SqlClient” />

</connectionStrings>


now modify web.config

<connectionStrings configSource=”myConfigsettings\devconnectionStrings.config”/>

<appSettings configSource=”myConfigsettings\devAppSettings.config” />
Similarly you can create as many config files for testing, production and change the name in Web.config

tstAppSettings.config

prdAppSettings.config


Tip: Unlike web.config,  these config files wont kill the session of current users if you accidentally enter a space and save the file.

Leave a Reply

Required fields are marked *.