gpt4 book ai didi

c# - Entity Framework 提供者错误

转载 作者:太空宇宙 更新时间:2023-11-03 21:06:03 28 4
gpt4 key购买 nike

大家好,我正在努力连接到 sql 数据库服务器。我正在使用 Entity Framework v6 并首次尝试代码优先方法。下面我将向您展示我的 app.config 文件和错误消息 我检查了类似的问题,大多数答案都是关于丢失 EntityFramework.SqlServer.dll 我有这个 dll引用

<?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>

错误信息:

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.

最佳答案

你找到解决这个问题的方法了吗?否则你可以在这里看看:Entity Framework Provider type could not be loaded?

大多数时候我看到此异常是因为 Web 应用程序没有安装 Entity Framework(和/或缺少 EntityFramework.SqlServer.dll)。

举个例子,如果你在一个解决方案中有 2 个项目:

  • 网络应用
  • 数据访问

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

  • WebApp 需要对 DataAccess 的引用
  • Webapp 还需要安装 EF

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

关于c# - Entity Framework 提供者错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41080182/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com