实体框架提供者错误 [英] Entity Framework provider error

查看:203
本文介绍了实体框架提供者错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我正在连接到sql数据库服务器。我第一次使用Entity框架v6并尝试代码第一种方法。下面我会告诉你我的 app.config 文件和错误消息我得到我查出类似的问题,大多数答案是关于缺少 EntityFramework.SqlServer。 dll 我有这个dll参考

 <?xml version =1.0encoding =utf -8\" >?; 
< configuration>
< configSections>
<! - 有关实体框架配置的更多信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468 - >
< section name =entityFrameworktype =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089requirePermission =false/> ;
< / configSections>
< startup>
< supportedRuntime version =v4.0sku =。NETFramework,Version = v4.5.2/>
< / startup>
< entityFramework>
< defaultConnectionFactory type =System.Data.Entity.Infrastructure.LocalDbConnectionFactory,EntityFramework>
< parameters>
< parameter value =mssqllocaldb/>
< / parameters>
< / defaultConnectionFactory>
< providers>
< provider invariantName =System.Data.SqlClienttype =System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer/>
< / providers>
< / entityFramework>
< connectionStrings>
< add name =HotelDB
connectionString =Data Source =(localdb)\v11.0; Initial Catalog = master; Integrated Security = True; Connect Timeout = 30; Encrypt = False; TrustServerCertificate = TRUE; ApplicationIntent =读写; MultiSubnetFailover =假/>
< / connectionStrings>
< / configuration>

错误消息:


System.InvalidOperationException:未找到具有不变名称System.Data.SqlClient的ADO.NET提供程序的实体框架提供程序。确保提供程序已注册在应用程序配置文件的entityFramework部分。请参阅 http://go.microsoft.com/fwlink/?LinkId=260882 更多信息。



解决方案

您是否找到了解决此问题的解决方案?否则你可以看看这里:实体框架提供者类型无法加载?



大多数时候,我看到这个异常是因为Web应用程序没有安装Entity Framework(和/或缺少 EntityFramework.SqlServer.dll )。所以举个例子,如果你在解决方案中有2个项目:




  • WebApp

  • DataAccess



并在DataAccess项目中安装了Entity Framework。当想从WebApp中的DataAccess项目中调用类(例如存储库)上的方法时,需要两件事:




  • WebApp需要参考DataAccess

  • Webapp还需要安装EF



当DataAccess有EF安装然后添加为WebApp的参考,WebApp项目将(通常)也安装EF。有时在意外情况下,在WebApp中安装EF失败。因此,不添加所需的引用并显示您提到的异常消息。希望这个答案会帮助别人。


Hello guys I am strugling with connecting to sql database server. I am using Entity framework v6 and trying code first approach for the first time. Below I will show you my app.config file and error message I get I checked out similar questions and most of answers were about missing EntityFramework.SqlServer.dll I have this dll referenced

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="HotelDB"
         connectionString="Data Source=(localdb)\v11.0;Initial Catalog=master;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"/>
  </connectionStrings>
</configuration>

Error Message:

System.InvalidOperationException: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

解决方案

Have you found a solution for this problem? Otherwise you could take a look here: Entity Framework Provider type could not be loaded?

Most of the time when I see this exception it's because the web application doesn't have Entity Framework installed (and / or missing the EntityFramework.SqlServer.dll).

So to give an example, if you have 2 projects in a solution:

  • WebApp
  • DataAccess

and with Entity Framework installed in the DataAccess project. When wanting to call a method on a class (for example a repository) from the DataAccess project within the WebApp, 2 things are needed:

  • WebApp needs a reference to DataAccess
  • Webapp also needs EF to be installed

When DataAccess has EF installed and then added as a reference to WebApp, the WebApp project will (normally) also install EF. Sometimes in unexpected situations the installation of EF in the WebApp failes. Therefore not adding the needed references and showing the exception message you mentioned. Hopefully this answer will help some others.

这篇关于实体框架提供者错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆