不变名称为“System.Data.SqlClient;”的ADO.NET提供程序无法找到(实体框架MVC) [英] ADO.NET provider with invariant name 'System.Data.SqlClient;' cannot be found (Entity Framework MVC)

查看:111
本文介绍了不变名称为“System.Data.SqlClient;”的ADO.NET提供程序无法找到(实体框架MVC)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法解决实体框架6中的一个常见问题。我已经在SO上审查了与此问题相关的许多主题,并且无法找到适用于我特定情况的解决方案。 >

直到这一点,我已经开发了使用localdb与代码第一次迁移,这很好。但是现在我把它移动到一个实际的SQL服务器实例,它会在尝试迁移时引发以下错误:



具有不变名称的System.Data的ADO.NET提供程序.SqlClient;'未在计算机或应用程序配置文件中注册,或无法加载。有关详细信息,请参阅内部异常。
在System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName)



我尝试了以下修复:



1)卸载和重新安装的实体框架



2)添加了



在上述每个步骤之后,清理/重建和删除现有迁移文件夹。



我很遗憾的解释为什么我还是收到此错误。



Web Config



 < section name =entityFrameworktype =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089 requirePermission =false/> 
<! - 有关实体框架配置的更多信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468 - >< / configSections>
< appSettings>
< add key =webpages:Versionvalue =3.0.0.0/>
< add key =webpages:Enabledvalue =false/>
< add key =ClientValidationEnabledvalue =true/>
< add key =UnobtrusiveJavaScriptEnabledvalue =true/>
< / appSettings>
< connectionStrings>

< add name =ReadContextconnectionString =Server = Sql2014intsnace; Database = database; User Id = secret; Password = secret;的providerName = System.Data.SqlClient的; />
< add name =WriteContextconnectionString =Server = Sql2014intsnace; Database = database; User Id = secret; Password = secret;的providerName = System.Data.SqlClient的; />
< / connectionStrings>
< system.web>
< compilation debug =truetargetFramework =4.5/>
< httpRuntime targetFramework =4.5/>
< authentication mode =Windows/>
<授权>
< deny users =? />
< / authorization>
< /system.web>
< system.webServer>
<处理程序>
< remove name =ExtensionlessUrlHandler-Integrated-4.0/>
< remove name =OPTIONSVerbHandler/>
< remove name =TRACEVerbHandler/>
< add name =ExtensionlessUrlHandler-Integrated-4.0path =*。 verb =*type =System.Web.Handlers.TransferRequestHandlerpreCondition =integratedMode,runtimeVersionv4.0/>
< / handlers>
< /system.webServer>
<运行时>
< assemblyBinding xmlns =urn:schemas-microsoft-com:asm.v1>
< dependentAssembly>
< assemblyIdentity name =Microsoft.OwinpublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-3.0.0.0newVersion =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =Microsoft.Owin.Security.OAuthpublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-3.0.0.0newVersion =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =Microsoft.Owin.Security.CookiespublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-3.0.0.0newVersion =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =Microsoft.Owin.SecuritypublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-3.0.0.0newVersion =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =Newtonsoft.Jsonculture =neutralpublicKeyToken =30ad4fe6b2a6aeed/>
< bindingRedirect oldVersion =0.0.0.0-6.0.0.0newVersion =6.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =System.Web.HelperspublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-3.0.0.0newVersion =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =System.Web.MvcpublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =0.0.0.0-5.2.2.0newVersion =5.2.2.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =System.Web.OptimizationpublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-1.1.0.0newVersion =1.1.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =System.Web.WebPagespublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =0.0.0.0-3.0.0.0newVersion =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =WebGreasepublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =0.0.0.0-1.5.2.14234newVersion =1.5.2.14234/>
< / dependentAssembly>
< / assemblyBinding>
< / runtime>
< entityFramework>
< defaultConnectionFactory type =System.Data.Entity.Infrastructure.SqlConnectionFactory,EntityFramework/>
< providers>
< provider invariantName =System.Data.SqlClienttype =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>


解决方案

你有这个:

 < add name =ReadContext
connectionString =Server = Sql2014intsnace; Database = database; User Id = secret; Password = secret;
providerName =System.Data.SqlClient; /> < - 分号

应该是这样的:

 < add name =ReadContext
connectionString =Server = Sql2014intsnace; Database = database; User Id = secret; Password = secret;
providerName =System.Data.SqlClient/> < - 无分号

否则,您告诉ADO找到名为 code> 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.

这篇关于不变名称为“System.Data.SqlClient;”的ADO.NET提供程序无法找到(实体框架MVC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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