ASP.NET MVC4 & Entity Framework 6.0 IIS 部署出錯解決方案

來源:互聯網
上載者:User

標籤: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 部署出錯解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.