Geeks With Blogs
mikedopp Geekswithblogs (edition)

I like the web.config it handles everything that a config file should. Including the fun of handling your data.

 1: <connectionStrings>
 2:  <add 
 3:  name="LocalSqlServer" 
 4:  connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" 
 5:  providerName="System.Data.SqlClient"
 6:  />
 7: </connectionStrings>

However if you develop like me you have three separated environments when writing a single app. Meaning you have to maintain a different web.config for every and every environment .

 1:  <!--Connectstrings config source points to YourSite.config for the source-->
 2:  <connectionStrings configSource="YourSite.config"/>
 
So Create a Config file outside the web.config for easy use. 
For example I upload the "YourSite.config" to the Dev, Test, Live servers.
Then you can either comment out the other connectionstings or make the string specific
to the enviroment.
 
YourSite.config:
 1: <connectionStrings>
 2:  <remove name="LocalSqlServer"/>
 3:  <clear/>
 4:  
 5:  <!--Live String-->
 6:  <!--<add name="yourSiteConnectionString" connectionString="Data Source=LiveServer;Initial Catalog=yourdbLive;Persist Security Info=True;User ID=hithere;Password=whatsnew" providerName="System.Data.SqlClient"/>-->
 7:  
 8:  <!--Test String-->
 9:  <add name="yourSiteTestConnectionString" connectionString="Data Source=TestServer;Initial Catalog=yourdbTest;Persist Security Info=True;User ID=hithere;Password=testing" providerName="System.Data.SqlClient"/>
 10:  
 11:  <!--Dev String-->
 12:  <!-- add name="yourSiteDevConnectionString" connectionString="Data Source=DevServer;Initial Catalog=yourdbDev;Persist Security Info=True;User ID=hithere;Password=deving" providerName="System.Data.SqlClient"/ -->
 13:  
 14:  </connectionStrings>
 
 
 

Posted on Friday, September 21, 2007 2:28 PM | Back to top


Comments on this post: Web.config and Connectionstrings a better way.

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © mikedopp | Powered by: GeeksWithBlogs.net