0

I have a .Net 4.5.1 Console application configured as a Windows Service (derives from ServiceBase), using EntityFramework 6.1 installed via the Nuget package.

It works fine running locally (where I run it as a console application).

I deploy it to a Windows Server 2008 machine which has .Net 4.5.2 installed, register it as a Windows Service, and successfully start the service.

The service has a timer that does work every 90 seconds. The first time it does work (after 90 seconds), when it attempts to read from a SQL Server database, it fails with this error message:

System.Configuration.ConfigurationErrorsException: The 'DbProviderFactories' section can only appear once per config file.

I looked into the 2 machine.config files on the machine (in the .Net 2 and 4 folders) and verified that each has only a single DbProviderFactories section. There is no DbProviderFactories in my service app.config. The EventViewer does not have any information. I reinstalled .Net 4.5.2 and restarted the server to no avail.

How can I find out where is it trying to load two DbProviderFactories sections?


I'm adding this next bit of information just in case it is germane.

The second time the service does work (after 180 seconds), when it attempts to read from the same SQL Server database it fails with a different error message:

The ADO.NET provider with invariant name 'System.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded.

This second error message is similar to this issue: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient' but unfortunately I've already implemented all the suggestions to fix it.

I installed Entity Framework 6 from the Nuget package in both my data access layer AND my Console App windows service. The NuGet installer inserted the required sections into my app.config:

<configSections>
  <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>

and

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  <providers>
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
  </providers>
</entityFramework>

I deployed what Visual Studio puts in my bin folder when I build. The deployment includes both EntityFramework.dll and EntityFramework.SqlServer.dll

My database connection string is:

<connectionString value="data source=SQLServerName;initial catalog=DatabaseName;integrated security=true;persist security info=True" />

The windows service runs under an identity that has access to the database.

This second error continues until I shut off the service.

Community
  • 1
  • 1
Tom Regan
  • 3,580
  • 4
  • 42
  • 71

1 Answers1

0

Turned out this was the answer: The 'DbProviderFactories' section can only appear once per config file

When I stated "I looked into the 2 machine.config files on the machine (in the .Net 2 and 4 folders) and verified that each has only a single DbProviderFactories section." that was false. There was a duplicate, I simply did not see it the first time I looked.

Community
  • 1
  • 1
Tom Regan
  • 3,580
  • 4
  • 42
  • 71