The Importance of Removing Elements from Web.Config

Published on December 15, 2011 | Filed Under ASP.NET

I admit it. I’m hard-headed. In fact, I tend to ignore simple programming rules, just because I think I’m great at paying attention. Unfortunately, even I make mistakes.

Recently, I was doing a website upload and my server finally caught on to one of my games: I had a sub-application with a web.config file that used the same connection string name as my main application. As far as ASP.NET and IIS are concerned, I shouldn’t have been allowed to get away with this. I suppose that night just wasn’t my night.

Since this was a sub-application, it wasn’t in my normal list of checks-and-balances for an after-upload run-through. So it wasn’t until the next morning that I received the following message:

The entry ‘MainConnection_Test’ has already been added.

Of course, my users had no clue what this error meant and my boss just wanted it to be fixed.

So how do you fix this error? Just add one line to your web.config file:

<remove name="MainConnection_Test" />

Place that just above your connection string.

So in a generic example, your web.config would look like this:

   <remove name="{Name}" />
   <add name="{Name}" connectionString="{String}"/>
   <remove name="{Name2}" />
   <add name="{Name2}" connectionString="{String}"/>

Just follow this rule for all of your connection strings.

So I have learned my lesson about taking two seconds to safeguard myself. Don’t fall into the same trap that I did!

~Derek Torrence

3 Responses to “The Importance of Removing Elements from Web.Config”

  1. HubertSuema says:

    Hey Look what we have for you! a fineoffering
    To qualify click on the link below

Leave a Reply