Wednesday, April 21, 2010

Referring to another config file in web.config file

Instead of having all connection string detail on web.config file , we can create a new configuration
whatEvernName.config eg(connectionString.config) and have all connection string details in this new .config file.

Please go through the code below to understand this.

web.config
<connectionStrings configSource="connectionString.config" />

connectionString.config
<connectionStrings
<
clear /> 
<
add name="myConnection" connectionString="myConnectionString" providerName="System.Data.SqlClient" /> </connectionStrings>

This is really nice feature when you have a lot of tags in your web.config file,
as it increases the readability. There is another cool feature which is very useful for
developers when it’s come to development or rather I would say debug the code.
Most of the times we have our connection string in one file and there is a high chance to forget
to change live connection string properties to test environment properties, I have made such a mistake and had to restore a latest database backup, but luckily there was not any data lost.

This cool feature avoids taking place such a bad mistake. Try this it’s is really nice and you do not have to keep on changing your web.config’s conection string values. As in above code snippet you can have two config files as connectionString.debug.config and connectionString.releaase.config

VS IDE will take the valuse depending on what you have selected, debug or release. Isn’t it cool.
Enjoy…

1 comments:

Avantha Siriwardana said...

hi

good job ;)

My Achievements

Member of

Blog Archive

Followers

free counters