C# Windows服务引用实体框架6在部署时失败

C# Windows服务引用实体框架6在部署时失败,c#,windows-services,entity-framework-6.1,C#,Windows Services,Entity Framework 6.1,我有一个.Net 4.5.1控制台应用程序,配置为从ServiceBase派生的Windows服务,使用通过Nuget软件包安装的EntityFramework 6.1 它在本地运行时运行良好,我将其作为控制台应用程序运行 我将其部署到安装了.Net 4.5.2的Windows Server 2008计算机上,将其注册为Windows服务,并成功启动该服务 该服务有一个计时器,每90秒工作一次。当它第一次在90秒后工作时,当它尝试从SQL Server数据库读取数据时,失败并显示以下错误消息:

我有一个.Net 4.5.1控制台应用程序,配置为从ServiceBase派生的Windows服务,使用通过Nuget软件包安装的EntityFramework 6.1

它在本地运行时运行良好,我将其作为控制台应用程序运行

我将其部署到安装了.Net 4.5.2的Windows Server 2008计算机上,将其注册为Windows服务,并成功启动该服务

该服务有一个计时器,每90秒工作一次。当它第一次在90秒后工作时,当它尝试从SQL Server数据库读取数据时,失败并显示以下错误消息:

System.Configuration.ConfigurationErrorsException: The 'DbProviderFactories' section can only appear once per config file.
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.
我查看了机器上.Net 2和4文件夹中的2个machine.config文件,并验证了每个文件都只有一个DbProviderFactorys部分。my service app.config中没有DbProviderFactorys。EventViewer没有任何信息。我重新安装了.Net 4.5.2并重新启动了服务器,但没有成功

我如何找到它试图加载两个DBProviderFactorys部分的位置

我将添加下一个信息,以防它是密切相关的

服务在180秒后第二次工作时,当它尝试从同一SQL Server数据库读取数据时失败,并显示不同的错误消息:

System.Configuration.ConfigurationErrorsException: The 'DbProviderFactories' section can only appear once per config file.
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.
第二条错误消息与此问题类似: 但不幸的是,我已经实施了所有的修复建议

我在我的数据访问层和我的控制台应用程序windows服务中安装了Nuget软件包中的Entity Framework 6。NuGet安装程序将所需的部分插入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>

我在构建时部署了VisualStudio放在bin文件夹中的内容。部署包括EntityFramework.dll和EntityFramework.SqlServer.dll

我的数据库连接字符串是:

<connectionString value="data source=SQLServerName;initial catalog=DatabaseName;integrated security=true;persist security info=True" />
windows服务在有权访问数据库的标识下运行


第二个错误一直持续到我关闭服务为止。

结果是答案是:

当我声明时,我查看了机器上.Net 2和4文件夹中的2个machine.config文件,并验证了每个文件都只有一个DbProviderFactorys部分。那是假的。有一个复制品,我第一次看的时候根本没看到