2016-12-10 286 views
1

你好傢伙我正在努力連接到SQL數據庫服務器。我正在使用Entity framework v6並首次嘗試使用代碼優先方法。下面我會告訴你我的app.config文件和錯誤消息我得到我檢查了類似的問題和答案,大部分都是關於失蹤EntityFramework.SqlServer.dll我有這個dll引用實體框架提供程序錯誤

<?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> 
    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> 
    </startup> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 
     <parameters> 
     <parameter value="mssqllocaldb" /> 
     </parameters> 
    </defaultConnectionFactory> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 
    <connectionStrings> 
    <add name="HotelDB" 
     connectionString="Data Source=(localdb)\v11.0;Initial Catalog=master;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"/> 
    </connectionStrings> 
</configuration> 

錯誤消息:

System.InvalidOperationException :未找到具有不變名稱「System.Data.SqlClient」的ADO.NET提供程序的實體框架提供程序。確保提供程序在應用程序配置文件的'entityFramework'部分中註冊。有關更多信息,請參見http://go.microsoft.com/fwlink/?LinkId=260882

回答

1

您是否找到了解決此問題的解決方案?否則你可以看看這裏:Entity Framework Provider type could not be loaded?

大多數時候,當我看到這個異常,這是因爲Web應用程序沒有安裝實體框架(和/或缺少EntityFramework.SqlServer.dll)。

因此,要舉一個例子,如果你有一個解決方案2個項目:安裝在數據訪問項目

  • 的WebApp
  • 數據訪問

,並與實體框架。想調用一個類中的方法(例如,儲存庫)從Web應用程序內的數據訪問項目時,需要兩兩件事:

  • Web應用程序需要數據訪問的參考
  • 的webapp也需要EF被安裝

當DataAccess安裝了EF並添加爲WebApp的引用時,WebApp項目(通常)也會安裝EF。有時在意外情況下,EF在WebApp中的安裝失敗。因此不添加所需的引用並顯示您提到的異常消息。希望這個答案能夠幫助其他人。

0

如果解決方案沒有任何效果,請檢查WebApp和DataAccess的packages.config以獲取實體框架版本。如果您在WebApp的packages.config文件中看到或未看到EF的條目,請轉到該參考並從WebApp中刪除EF,然後使用軟件包管理器控制檯再次安裝,並提供以下命令:

安裝包「EntityFramework」-Version(版本號) 其中,版本號是DataAccess的packages.config中存在的版本。例如: 安裝包「EntityFramework」 - 版本「6.1。3"

0

我也有過類似的問題

我的問題是通過以下操作解決:

enter image description here

enter image description here

+1

請不要發佈相同的答案多個問題發表一個很好的答案,然後投票/標記將其他問題作爲重複項目關閉。如果問題不是重複的,*定製你對問題的答案。* –