实体框架适用于本地服务器,但不适用于远程

Ken*_*Ken 5 asp.net entity-framework

好的,我有一个使用ASP.net mvc的网站,我遇到的问题是实体框架.我添加了所有引用并让它在我的本地计算机上运行但是当我发布它时出现以下错误.

System.InvalidOperationException:实体框架提供程序为'System.Data.SqlClient'ADO.NET输入'System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'提供程序无法加载.确保提供程序程序集可用于正在运行的应用程序.有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=260882.

我已经仔细检查了我的引用,并且我将EntityFramework.SqlServer和System.Data都添加到了我的项目中.我用来连接数据库并声明服务提供的连接字符串如下所示.

<connectionStrings>
<add name="[dataConnection]" connectionString="Data Source=[ip of host machine];Database=[name];UID=[user];pwd=*******;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
  </connectionStrings>
Run Code Online (Sandbox Code Playgroud)

名称我们只有数据库的名称,这也在我的web.debug.config中使用

<connectionStrings>
<add name="[dataconnection]"
  connectionString="Data Source=.;Database=[name];UID=[user];pwd=*******;MultipleActiveResultSets=True;"
  xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  </connectionStrings>
Run Code Online (Sandbox Code Playgroud)

我对这整个事情都很陌生,只是把别人的代码递给了我,所以我正在努力学习这个流程.这是我第一次遇到这个,所以任何方向都会受到赞赏.

Vas*_*kin 7

我在集成测试程序集中遇到了同样的问题(我正在使用ms visual studio单元测试框架),我通过在.testsettings文件中为部署项添加EF程序集来解决它.

  1. 我使用Package Manager Console安装了EF 6 alpha,使用:Install-Package EntityFramework -Pre

这是我的app.config

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
      </entityFramework>
    </configuration>
Run Code Online (Sandbox Code Playgroud)

我的连接字符串(我在代码中设置它): server=.\SIN;initial catalog=IntegrationTests;User ID=user;Password=pass;MultipleActiveResultSets=true;

  1. 我查看了EF程序集引用属性,看它们是否设置为"Copy Local"= True.最后我检查了TestResults /../ Out文件夹,发现那里没有EntityFramework.SqlServer程序集(SqlProviderServices类驻留在其中).

  2. 所以我刚刚将两个EF 6程序集添加到我的部署项目中,现在一切正常 部署项目

您可以尝试将EntityFramework.SqlServer程序集复制到Web服务器目录以查看它是否有效.

也许这个链接可能会有所帮助

PS:

确保您没有对System.Data.Entity的引用,因为您将使用GAC中的一个.使用Nuget安装时,未在GAC中安装EF 6 Alpha程序集.目标框架应该是.NET 4.5.

对不起,我的英语不好.