Tag Archives: .Net 4.0

DbProviderFactories section can only appear once per config file

Recently I came across this error while doing some housekeeping and updating some old websites to .Net 4.0:

HttpException: Failed to generate code. The ‘DbProviderFactories’ section can only appear once per config file.

The problem is with the machine.config file in the .Net 4.0 folder on the hosting server. For some reason, an additional <DbProviderFactories /> element is present and needs to be removed.

  • On the affected server, open C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config in your favorite editor (Also might want to check C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config)
  • Scroll down about halfway to the <system.data> section
  • Look for the <DbProviderFactories> element, which should already contain various connection providers. Right after the closing </DbProviderFactories> element there is most likely another empty element that looks like this:
    <system.data>
            <DbProviderFactories>
                <add name="Provider Name" invariant="Something" description=".NET Framework Data Provider for Something" type="Type, Desc, Version, Culture=neutral, PublicKeyToken=token" />
            </DbProviderFactories>
            <DbProviderFactories />
        </system.data>

    Delete the <DbProviderFactories /> line right before the closing <system.data>. It should look like this now:

    
            <DbProviderFactories>
                <add name="Provider Name" invariant="Something" description=".NET Framework Data Provider for Something" type="Type, Desc, Version, Culture=neutral, PublicKeyToken=token" />
            </DbProviderFactories>
        </system.data>
  • Save the file and restart IIS on the affected server

That should solve that issue. In rare cases I’ve had to restart the entire server, but usually bouncing IIS afterwards is good enough. Hope this helps!

Eric Oszakiewski

Eric Oszakiewski is a professional software developer based in Scottsdale, AZ with over 36 years of IT experience, and 19 years Native American Gaming experience. He is currently working as a Sr .Net/SharePoint Development Lead for General Motors, and also as a consultant.

More Posts

Follow Me:
TwitterFacebookLinkedInGoogle PlusYouTube

STM and .Net 4.0 Beta 1

I installed STM.Net this past week (Software Transactional Memory) as a experimental trial from DevLabs. Although I’m not sure how this environment will help my current enterprise I work for, I’m still curious about learning something new. I haven’t had a chance to try out the code yet this week, but hopefully next week after I set up my new dev environment at work I can install it there too and give it a whirl. I’ll post something here once I have some time to mess with it. If anyone who’s tried this already has any feedback or comments please feel free to post them below.

Eric Oszakiewski

Eric Oszakiewski is a professional software developer based in Scottsdale, AZ with over 36 years of IT experience, and 19 years Native American Gaming experience. He is currently working as a Sr .Net/SharePoint Development Lead for General Motors, and also as a consultant.

More Posts

Follow Me:
TwitterFacebookLinkedInGoogle PlusYouTube