有固定名称ADO.NET提供'System.Data.SqlClient的;“无法找到(实体框架MVC) [英] ADO.NET provider with invariant name 'System.Data.SqlClient;' cannot be found (Entity Framework MVC)
问题描述
我似乎无法化解这似乎是与实体框架的共同问题6.我已审查有关这一问题上让许多话题,而我无法找到我的特定情况下的解决方案。
我直到这一点已使用的LocalDB与code首先迁移,这工作得很好发展。但现在,我提出这在试图迁移它抛出了以下错误实际的SQL Server实例:
以不变名ADO.NET提供'System.Data.SqlClient的;或者未在本机或应用程序的配置文件注册,或无法加载。详情请参阅内部异常。
在System.Data.Common.DbProviderFactories.GetFactory(字符串providerInvariantName)
我已尝试以下修正:
1)卸载并重新安装实体框架
2)增加了 code 一>并用:
公共抽象类BaseDomainContext:的DbContext
{
静态BaseDomainContext()
{
// ROLA - 这是一个黑客,以确保实体框架SQL提供跨到输出文件夹复制。
//因为它是安装在GAC中,复制本地不起作用。它是必需的,用于探测。
//修正提供未加载错误
VAR ensureDLLIsCopied = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
}
}
作为我DbSet类的基类。
3)增加了一切新的解决方案,并获得同样的错误。
与4)删除了writecontext并试图迁移刚刚看了,还是失败了。
5)试图重写几个利用 MSDN
6)我已经证实,EntityFramework.SqlServer.dll是在我的bin目录中。它也被正确引用。另外,我只有一个项目在我的解决方案。
7)我不使用下享有WebConfig证实。
8)证实我有System.Data这DLL在bin文件夹中。
清洁/重建和现有的迁移删除文件夹中每个以上步骤之后进行。
我茫然地解释为什么我还是我收到此错误。
Web配置
<节名称=的EntityFrameworkTYPE =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,的EntityFramework,版本6.0.0.0 =文化=中性公钥= b77a5c561934e089 requirePermission =FALSE/>
<! - 有关Entity Framework的配置的详细信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468 - >< / configSections>
<&的appSettings GT;
<添加键=网页:版本值=3.0.0.0/>
<添加键=网页:启用VALUE =FALSE/>
<添加键=ClientValidationEnabledVALUE =真/>
<添加键=UnobtrusiveJavaScriptEnabledVALUE =真/>
< /的appSettings>
<&是connectionStrings GT; <添加名称=ReadContext的connectionString =服务器= Sql2014intsnace;数据库=数据库;用户ID =秘密;密码=秘密;的providerName =System.Data.SqlClient的; />
<添加名称=WriteContext的connectionString =服务器= Sql2014intsnace;数据库=数据库;用户ID =秘密;密码=秘密;的providerName =System.Data.SqlClient的; />
< /&是connectionStrings GT;
<&的System.Web GT;
<编译调试=真targetFramework =4.5/>
<的httpRuntime targetFramework =4.5/>
<身份验证模式=窗口/>
<授权>
<拒绝用户=? />
< /授权>
< /system.web>
< system.webServer>
<&处理GT;
<清除NAME =ExtensionlessUrlHandler - 集成 - 4.0/>
<清除NAME =OPTIONSVerbHandler/>
<清除NAME =TRACEVerbHandler/>
<添加名称=ExtensionlessUrlHandler - 集成 - 4.0PATH =*。动词=*类型=System.Web.Handlers.TransferRequestHandlerpreCondition =integratedMode,runtimeVersionv4.0/>
< /处理器>
< /system.webServer>
<&运行GT;
< assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1>
< dependentAssembly>
< assemblyIdentity名称=Microsoft.Owin公钥=31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-3.0.0.0NEWVERSION =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=Microsoft.Owin.Security.OAuth公钥=31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-3.0.0.0NEWVERSION =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=Microsoft.Owin.Security.Cookies公钥=31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-3.0.0.0NEWVERSION =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=Microsoft.Owin.Security公钥=31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-3.0.0.0NEWVERSION =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=Newtonsoft.Json文化=中性公钥=30ad4fe6b2a6aeed/>
< bindingRedirect oldVersion =0.0.0.0-6.0.0.0NEWVERSION =6.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=System.Web.Helpers公钥=31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-3.0.0.0NEWVERSION =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=System.Web.Mvc公钥=31bf3856ad364e35/>
< bindingRedirect oldVersion =0.0.0.0-5.2.2.0NEWVERSION =5.2.2.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=System.Web.Optimization公钥=31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-1.1.0.0NEWVERSION =1.1.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=System.Web.WebPages公钥=31bf3856ad364e35/>
< bindingRedirect oldVersion =0.0.0.0-3.0.0.0NEWVERSION =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=WebGrease公钥=31bf3856ad364e35/>
< bindingRedirect oldVersion =0.0.0.0-1.5.2.14234NEWVERSION =1.5.2.14234/>
< / dependentAssembly>
< / assemblyBinding>
< /运行>
<&的EntityFramework GT;
< defaultConnectionFactory TYPE =System.Data.Entity.Infrastructure.SqlConnectionFactory,的EntityFramework/>
<供应商>
<供应商invariantName =System.Data.SqlClient的TYPE =System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer/>
< /供应商>
<&上下文GT;
<上下文类型=ProjectName.Models.ReadContext,项目名>
< databaseInitializer TYPE =System.Data.Entity.MigrateDatabaseToLatestVersion`2 [ProjectName.Models.ReadContext,项目名],[ProjectName.Migrations.Configuration,项目名]]的EntityFramework/>
< /背景>
< /背景>
< /&的EntityFramework GT;
< /结构>
您有这样的:
<添加名称=ReadContext
的connectionString =服务器= Sql2014intsnace;数据库=数据库;用户ID =秘密;密码=秘密;
的providerName =System.Data.SqlClient的; /> < - 分号
应该是这样的:
<添加名称=ReadContext
的connectionString =服务器= Sql2014intsnace;数据库=数据库;用户ID =秘密;密码=秘密;
的providerName =System.Data.SqlClient的/> < - 无分号
否则,你告诉ADO找到一个名为提供商 System.Data.SqlClient的;
- 没有一个
I cannot seem to resolve what appears to be a common issue with Entity Framework 6. I have reviewed the many topics related to this issue on SO, and am unable to find a solution that works for my particular case.
I have up until this point been developing using localdb with code first migrations, which worked fine. But now that I am moving this to a actual SQL server instance it throws the following error while attempting migrations:
"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. at System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName)"
I have attempted the following fixes:
1) Uninstalled and Reinstalled Entity Framework
2) Added the code and used :
public abstract class BaseDomainContext : DbContext
{
static BaseDomainContext()
{
// ROLA - This is a hack to ensure that Entity Framework SQL Provider is copied across to the output folder.
// As it is installed in the GAC, Copy Local does not work. It is required for probing.
// Fixed "Provider not loaded" error
var ensureDLLIsCopied = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
}
}
as the base class for my DbSet classes.
3) Added everything to a fresh solution and received the same error.
4) Removed the writecontext and tried migrations with just read, still failed.
5) Attempted several rewrites using information from MSDN
6) I have confirmed that EntityFramework.SqlServer.dll is in my bin directory. It is also referenced properly. Plus I have only one project under my solution.
7) Confirmed I am not using the WebConfig under views.
8) Confirmed I have System.Data dll in bin folder.
Clean/Rebuilding and deletion of existing migrations folder done after each of the above steps.
I am at a loss to explain why I still am receiving this error.
Web Config
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<connectionStrings>
<add name="ReadContext" connectionString="Server=Sql2014intsnace;Database=database;User Id=secret; Password=secret;" providerName="System.Data.SqlClient;" />
<add name="WriteContext" connectionString="Server=Sql2014intsnace;Database=database;User Id=secret; Password=secret;" providerName="System.Data.SqlClient;" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
</system.web>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
<contexts>
<context type="ProjectName.Models.ReadContext, ProjectName">
<databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[ProjectName.Models.ReadContext, ProjectName], [ProjectName.Migrations.Configuration, ProjectName]], EntityFramework" />
</context>
</contexts>
</entityFramework>
</configuration>
You have this:
<add name="ReadContext"
connectionString="Server=Sql2014intsnace;Database=database;User Id=secret; Password=secret;"
providerName="System.Data.SqlClient;" /> <-- semi-colon
It should be this:
<add name="ReadContext"
connectionString="Server=Sql2014intsnace;Database=database;User Id=secret; Password=secret;"
providerName="System.Data.SqlClient" /> <-- no semi-colon
Otherwise, you're telling ADO to find a provider named System.Data.SqlClient;
- there isn't one.
这篇关于有固定名称ADO.NET提供'System.Data.SqlClient的;“无法找到(实体框架MVC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!