Better Late Than Never.....

 I’ve had several people ask why I don’t have a blog out there yet. My standard response has always been that I just don’t have enough time (which is true most days) between running my consulting business, training, spending time with my wife and kids, running the http://www.xmlforasp.net website, writing, etc., etc..  However, after reading more and more blogs from a variety of people I’ve come to the conclusion that creating a blog is a great way to help out others (when the blog is technology related….sorry but I don’t have much to offer in the area of self-help J) plus is a great way to track different things that have been worked on.  

I don’t know how many times I’ve figured out a solution to an issue only to experience the same issue several months later.  The problem is (due to hitting the ripe old age of 34 I guess) I can’t remember how I fixed the original problem sometimes.  So, I’m hoping to start blogging about a few of the different things I come across.  While I’ll never be the blogger that Sam Gentile is (the guy is amazing), I’ll try to post a few things from time to time that will hopefully be of value to someone out there.

For those dealing with managing multiple connection strings in development, QA, and production environments I’ve recently posted a new code sample to the XML for ASP.NET Developers Website (http://www.xmlforasp.net) titled “Manage Development and Production Database Connection Strings with XML Serialization”.  It makes it simple to handle connection strings without renaming web.config files when moving to a different environment or introducing potential human error into the deployment process.  The code relies on XML serialization (one of my favorite technologies in .NET) and provides an object named ServerConfigManager that allows server data to be accessed (such as proxy or mail servers), connection strings to be accessed that are dynamically located based upon the server domain, plus more.  Here’s an example of using the ServerConfigManager to access connection strings:

static string _Database = "Northwind"; 
static string _PrimaryConnStr =
ServerConfigManager.GetConnectionString(_Database).Primary;
static string _SecondaryConnStr =
ServerConfigManager.GetConnectionString(_Database).Secondary;
We use it for everything at my contract site and have found the model both easy to use and quite efficient. 
The complete code can be downloaded from http://www.xmlforasp.net/CodeSection.aspx?csID=111.

 

comments powered by Disqus

2 Comments

  • Another way that I have seen people get around the web.config file copying is to use the machine.config or web.config and set an appSetting called Environment. Environment is the kind of server (dev, test, prod,etc.). Then the create a config class with a static method to get the Environment and static methods for each of the value in the web.config. The method for each web.config value appends in the output from the Environment method. So in the methods you would look for ConfigurationSettings.AppSettings[Environment + "MyWebConfigValue"] and then in the web.config you would have DevelopmentMyWebConfigValue, TestMyWebConfigValue, etc.



    Then anywhere in the code that you need to access the values, you just call the static method (e.g. Configs.MyWebConfigValue.

  • Welcome, my friend!

Comments have been disabled for this content.