加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

ASP.NET MVC4 & Entity Framework 6.0 IIS 部署出错解决方

发布时间:2020-12-13 20:12:27 所属栏目:PHP教程 来源:网络整理
导读:近期了解MVC4的时候弄了1个简单的小工程,使用Entity Framework作为Model,F5启动调试运行的时候没有问题,但是发布到IIS以后访问就报错 毛病信息以下: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices,EntityFrame

近期了解MVC4的时候弄了1个简单的小工程,使用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.

很奇怪,搜索了1下,找到1个老外的帖子,戳这里

解决方案以下:

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

不明所以,具体缘由还是不清楚,这个方法也历来未被调用过,但是。。。好用了!

此解决方案还需要后续进行观测,毕竟修改的是根据数据库生成的文件。

还有1种方案我没有尝试,可以强迫部署EntityFramework.SqlServer.dll这个文件到输出目录,有兴趣的可以尝试。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读