2

我似乎无法化解这似乎是与实体框架的一个常见问题6.我已经审查了与这个问题上,因此将许多话题,而我无法找到适合有效的解决方案我的特殊情况。ADO.NET提供者System.Data.SqlClient的;“无法找到(实体框架MVC)

我一直在使用localdb开发代码优先迁移,这工作得很好。但是现在我将它移动到实际的SQL服务器实例,它在尝试迁移时会引发以下错误:

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

我已尝试以下修正:

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

2)增加了code和使用:

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; 
    } 
} 

作为用于我的DbSet基类类。

3)添加的一切新溶液和接收到的同样的错误。

4)删除了writecontext,并尝试迁移只读,仍然失败。

5)试图重写几个利用MSDN

6信息)我已经证实,EntityFramework.SqlServer.dll是在我的bin目录。它也被正确引用。另外,我只有一个在我的解决方案项目。

7)确认我没有在视图下使用WebConfig。

8)确认我有System.Data dll bin文件夹中。

Image of bin folder

清洁/再造与现有的迁移删除文件夹中每个的上述步骤之后进行。

我茫然地解释为什么我还是我收到此错误。

Web配置

<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> 
+0

听起来像缺少'System.Data.dll' – jsanalytics

+0

我添加了更多信息,请参阅bin文件夹的图像。它正在复制。 – Rasen244

+0

是的,那确实是问题所在。 – Rasen244

回答

8

你有这样的:

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

它应该是这样的:

<add name="ReadContext" 
    connectionString="Server=Sql2014intsnace;Database=database;User Id=secret; Password=secret;" 
    providerName="System.Data.SqlClient" /> <-- no semi-colon 

否则,你告诉ADO找到提供者nam ED System.Data.SqlClient; - 没有之一。

-1

对于我来说,这个问题是由损坏的EntityFramework引起的。卸载EntityFramework以及Visual Studio并重新安装Visual Studio - Visual Studio安装涵盖了解决此问题的.Net Framework SDK安装类型。

+1

不,从字面上看,我包含了一个分号。尽管在我指出错字之前,我自己尝试了解决方案。 – Rasen244

0

我得到了这个错误,但对我来说这是完全不同的东西。我可以通过看仅Unable to find the requested .Net Framework Data Provider并找到这个答案来解决这个问题:

https://stackoverflow.com/a/9929534/3850405

我只好再编辑:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config 

和:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config 

搜索DbProviderFactories两个配置都是这样的:

<system.data> 
    <DbProviderFactories> 
     <add name="IBM DB2 for i .NET Provider" invariant="IBM.Data.DB2.iSeries" description=".NET Framework Data Provider for IBM i" type="IBM.Data.DB2.iSeries.iDB2Factory, IBM.Data.DB2.iSeries, Version=12.0.0.0, Culture=neutral, PublicKeyToken=9cdb2ebfb1f93a26" /> 
    </DbProviderFactories> 
    <DbProviderFactories /> 
</system.data> 

当我删除尾部<DbProviderFactories />一切都开始工作了。

相关问题