18. June 2009 09:44
Another way to store your connection string in a way that it doesn't get in the way when you promote your web site from Test to QA to Prod is the following:
Have your web site under a given directory, say d:\WebSites\MyWebsite.
And you also have another directory to hold your connection strings that isn't under that directory. So I could have my connection string as an appSetting in the following file:
The section looks like:
<add key="Env" value="Dev"/>
<add key="DefaultConnection" value="server=MyServer;uid=MyUser;pwd=P@ssw0rd;database=MyDB;" />
Then you have the following in your d:\WebSites\MyWebsite\web.config file
You would retreive the string by:
-Things to note are that this now allows you to delete everything under d:\WebSites\MyWebsite before you redeploy your site.
-If you change the connection string you need to do an IIS reset for the site to pick up the change.
-You can't do the file="..." part with a connection