Entity Framework 6.0 IIS 部署出错解决方案

我自己写的webAPI + EF6.0 本地运行正常,部署到Windows Server2008中的IIS7.5中报错。

报错信息如下:

"Message":"出现错误。","ExceptionMessage":"无法为具有固定名称“System.Data.SqlClient”的 ADO.NET 提供程序加载在应用程序配置文件中注册的实体框架提供程序类型“System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer”。请确保使用限定程序集的名称且该程序集对运行的应用程序可用。

 

解决方法:

1.发现.netframework只有2.0的。于是装了4.5版本。

2.网络上找的方法:

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

 

然后,重启服务器,搞定!!!

 

posted @ 2015-09-23 13:26  步子521  阅读(541)  评论(0编辑  收藏  举报