No Entity Framework provider found for the ADO.NET provider with invariant name #39;System.Data.SqlClient#39;.(找不到具有不变名称“System.Data.SqlClient的 ADO.NET 提供程序的实体框架提供程序.)
问题描述
我们正在使用带有 Code First 的 EntityFramework 6.我们有一个控制台应用程序,它没有引用 EntityFramework,但从其 App.config 中读取连接字符串.它调用 DatabaseInitializationUtilities 程序集,将连接字符串作为参数传递.
We are using EntityFramework 6 with Code First. We have a console app that has no reference to EntityFramework but reads the connection string from its App.config. It calls the DatabaseInitializationUtilities assembly passing the connection string as a parameter.
DatabaseInitializationUtilities 引用了 EF6(EntityFramework 和 EntityFramework.SqlServer).它的 App.config 是这样的:
DatabaseInitializationUtilities has the reference to EF6 (EntityFramework and EntityFramework.SqlServer). Its App.config is this:
<?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>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IAuthentication" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/SecurityServices/Authentication.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAuthentication" contract="SecurityService.IAuthentication" name="BasicHttpBinding_IAuthentication" />
</client>
</system.serviceModel>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
当执行到达 DatabaseInitializationUtilities 尝试运行脚本的行时
When execution reaches a line where DatabaseInitializationUtilities attempts to run a script
context.Database.ExecuteSqlCommand(script.ScriptText)
抛出错误:
找不到具有不变名称System.Data.SqlClient"的 ADO.NET 提供程序的实体框架提供程序.确保提供程序已在应用程序配置文件的entityFramework"部分注册.请参阅 http://go.microsoft.com/fwlink/?LinkId=260882 了解更多信息.
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.
我相信补救措施正是我的配置文件中的内容,所以我不明白这个问题.
I believe the remedy is exactly what I have in my config file, so I don't understand the problem.
注意:Resharper 正在蓝化节点并报告"元素 'EntityFramework' 的子元素 'providers' 无效.但是,当我安装 EF6 时,该部分是由 NuGet 注入的.
NOTE: Resharper is bluelining the node and reporting "The element 'EntityFramework' has an invalid child element 'providers'. However, the section was injected by NuGet when I installed EF6.
有什么想法吗?
推荐答案
你需要创建一个引用,所以它会被复制到调试文件夹中.所以稍后它可以在运行时访问.
You need to create a reference, so it will be copied in the debug folder. So later it can accessed in runtime.
不要复制任何文件,只需创建此引用:
Don't to copy any files, just create this reference:
private volatile Type _dependency;
public MyClass()
{
_dependency = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
}
这篇关于找不到具有不变名称“System.Data.SqlClient"的 ADO.NET 提供程序的实体框架提供程序.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:找不到具有不变名称“System.Data.SqlClient"的 ADO.NET 提供程序的实体框架提供程序.
基础教程推荐
- SSE 浮点算术是否可重现? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- c# Math.Sqrt 实现 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01