DbProviderFactories section can only appear once per config file

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!

4 thoughts on “DbProviderFactories section can only appear once per config file

  1. Thank you very much Eric.
    I solved the problem.
    In my case it was produced after the iseries client access installation, and the problem appeared when I tried edit a table in SSMS y SQL Server.
    Thank you again.

Comments are closed.

Comments are closed.