实体框架ADO.NET Sql.Data.Client提供程序未找到 [英] Entity Framework ADO.NET Sql.Data.Client provider not found
问题描述
我有一个类似的问题,在问题
未找到具有不变名称System.Data.SqlClient的ADO.NET提供程序的实体框架提供程序,错误具有以下消息:
I have a similar problem as the one presented in the question No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient', the error has the following message:
具有不变名称System.Data.SqlClient的ADO.NET提供程序未在计算机或应用程序配置文件中注册,或无法加载,请参阅内部异常详细信息。
"The ADO.NET provider with invariant name 'System.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details."
由于相关问题的答案建议,我通过包管理器控制台重新安装了实体框架(EF6),但是错误仍然存在。我还检查了项目中引用了EntityFramework.SqlServer.dll。
这是存储在App.config中的连接字符串:
As the answers to the related question suggest, I have reinstalled Entity Framework (EF6) via the Package Manager Console, but the error persists. I also checked that EntityFramework.SqlServer.dll is referenced in my project. Here is the connection string as stored in App.config:
<add name="DesignModel" ConnectionString="metadata=res://*/DesignModel.csdl|res://*/DesignModel.ssdl|res://*/DesignModel.msl;provider=System.Data.SqlClient;provider connection string="data source=C071E;initial catalog=CTD2;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
我有另一个项目,我使用EntityFramework创建完全相同的实体和上下文,它工作正常,这使得这更令人费解。
I have another project where I used EntityFramework to create the exact same entities and context, and it works fine, which makes this all more puzzling.
尝试执行此行时会显示错误:
The error is shown when trying to execute this lines:
DesignModel designContext = new DesignModel();
designContext.MoPerfIDs.Load();
其中DesignModel是继承DbContext的类的名称。
where DesignModel is the name of the class that inherits DbContext.
这是完整的App.config:
Here's the full App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="ppe.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
<!-- 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>
<connectionStrings>
<add name="DesignModel" connectionString="metadata=res://*/DesignModel.csdl|res://*/DesignModel.ssdl|res://*/Design Model.msl;provider=System.Data.SqlClient;provider connection string="data source=MONNMC071E;initial catalog=CTD2;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlClient" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
任何帮助将不胜感激。感谢提前。
Any help will be appreciated. Thanks in advance.
推荐答案
您需要注册System.Data.SqlClient SQL连接类型的实体框架提供程序。
你应该在app.config中:
You need to register the Entity Framework provider for the System.Data.SqlClient SQL connection type. you should have in app.config:
<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>
<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>
这篇关于实体框架ADO.NET Sql.Data.Client提供程序未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!