at System.Data.EntityClient.EntityConnection.GetFactory(String providerString)

最近在做一个WinForm的项目. 使用vs2013开发. 数据库使用的是oracle. 在本地写了一个webservice .测试正常.发布到服务器的时候.就是提示了错误. 打开服务器上的日志.看到如下信息:

System.ArgumentException: The specified store provider cannot be found in the configuration, or is not valid. ---> System.ArgumentException: Unable to find the requested .Net Framework Data Provider.  It may not be installed.
   at System.Data.EntityClient.EntityConnection.GetFactory(String providerString)
   --- End of inner exception stack trace ---
   at System.Data.EntityClient.EntityConnection.GetFactory(String providerString)
   at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
   at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
   at System.Data.Entity.Internal.LazyInternalConnection.get_Connection()
   at Kerry.FW.Service.SecurityService.GetAuthenticateUserDetail(String userName, String password, String& errorMessage) in c:K4Kerry.K4Kerry.FW.ServiceSecurityService.svc.cs:line 57

开头有点纳闷. 因为之前做过另外一个系统 .也是使用EntityFramework , 数据库使用Oracle的.可以在服务器上正常运行.  所以认为oracle 驱动没注册的应该不大可能.结果看到了这篇文章

http://blog.csdn.net/greystar/article/details/9057159

里面提到了一种情况.就是在不同位(32bit/64bit)系统上开发时,visual studio 调用的机器配置文件 machine.config是不一样的. 而我恰恰也就是原先机器使用的是32位 来进行开发. 最近刚换到了 64位.

文中重点提到了

  32位的machine.config 放在的是 (不同.NET Framework 版本对应不同的文件夹)

  C:WindowsMicrosoft.NETFrameworkv4.0.30319Configmachine.config

64位的machine.config 放在

  C:WindowsMicrosoft.NETFramework64v4.0.30319Configmachine.config

出现驱动未注册的问题原因是 64位中的config 里面的system data 未配置一下内容

  

  <system.data>
    <DbProviderFactories>
      <add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
      <add name="ODP.NET, Unmanaged Driver" invariant="Oracle.DataAccess.Client" description="Oracle Data Provider for .NET, Unmanaged Driver" type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
      <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
    </DbProviderFactories>
  </system.data>

我尝试在服务器上面加上这一段. 然后重新运行. 测试结果正常.

当然另外一种方式就是将当前的项目目标生成平台改位x86. 

前几天 碰到另外一种情况, 也可以能导致这个问题. 服务器上IIS应用池设置:

当应用池中的 Enable 32-Bit Application  为false 时 也可能会导致 这个问题.  重新修改为True  为 即可以正常解决

PS 关于Machine.config 的作用   http://www.cnblogs.com/dimg/archive/2005/11/12/274648.html

原文地址:https://www.cnblogs.com/weeky/p/4046363.html