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

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

More Posts - Website

Follow Me:
TwitterFacebookLinkedInGoogle PlusYouTube

Filenames and WebDAV in SharePoint 2010

This is more of a reminder to myself than anything, and you may already be aware of this, but in case this issue is new here’s what helped me:

While taking our enterprise in a paperless direction, one department was having trouble opening a document library using the “Open in Windows Explorer” function every time they saved a certain file to it. For the longest time I couldn’t find any pattern to the behavior, and assumed it was something to do with the file. Turns out it was the filename itself. In this case, they were using the word “Service” in the filename, namely “<dept name> Service Request.pdf”. The word “Service” isolated in the filename was screwing up WebDAV as it was trying to open the document library in a Windows Explorer view. Once they either removed the word “Service”, altered it (Svc, Serv., etc) or ran the whole thing together (deptservicerequest.pdf) the issue was resolved.

Never would have assumed “Service” is in a round-about way a protected word, like using the word “table” in a SQL query, but apparently it is! Would love to learn more about WebDAV to better understand why this is so, and if there are any other words that should be avoided.

Hope this helps!

Eric

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

More Posts - Website

Follow Me:
TwitterFacebookLinkedInGoogle PlusYouTube