標籤:asp.net mvc entity framework
近期瞭解MVC4的時候弄了一個簡單的小工程,使用Entity Framework作為Model,F5啟動調試啟動並執行時候沒有問題,但是發布到IIS之後訪問就報錯
錯誤資訊如下:
The Entity Framework provider type ‘System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer‘ registered in the application config file for the ADO.NET provider with invariant name ‘System.Data.SqlClient‘ could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application.
很奇怪,搜尋了一下,找到一個老外的文章,戳這裡
解決方案如下:
在EF的上下文代碼CS檔案(Model1.Context.cs)中添加這個方法
public void FixEfProviderServicesProblem(){//The Entity Framework provider type ‘System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer‘//for the ‘System.Data.SqlClient‘ ADO.NET provider could not be loaded. //Make sure the provider assembly is available to the running application. //See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.var instance = System.Data.Entity.SqlServer.SqlProviderServices.Instance;}
不明所以,具體原因還是不清楚,這個方法也從來未被調用過,但是。。。好用了!
此解決方案還需要後續進行觀測,畢竟修改的是根據資料庫產生的檔案。
還有一種方案我沒有嘗試,可以強制部署EntityFramework.SqlServer.dll這個檔案到輸出目錄,有興趣的可以嘗試。
ASP.NET MVC4 & Entity Framework 6.0 IIS 部署出錯解決方案