错误:连接未关闭。连接的当前状态是连接

时间:2015-11-29 19:25:02

标签: entity-framework iis model-view-controller

我有MVC-Api(实体框架),我最近开始遇到这种错误。 (不是所有的时间)

System.Data.EntityException: The underlying provider failed on Open. ---> System.InvalidOperationException: The connection was not closed. The connection's current state is connecting.

System.Data.EntityException: The underlying provider failed on Open. ---> System.InvalidOperationException: The connection was not closed. The connection's current state is open.

//web.config
<add name="Entities" providerName="System.Data.EntityClient"  connectionString="metadata=res://*/Models.Model.csdl|res://*/Models.Model.ssdl|res://*/Models.Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost ;Initial Catalog=MyDB;Integrated Security=SSPI;Application Name=Api;MultipleActiveResultSets=True;&quot;" />
//Run on IIS as local system.

从Global.asax开始,连接已注册LifestylePerWebRequest模式。

//registered
public static void RegDbContext()
{
  Container.Register(Component.For<Entities>().LifestylePerWebRequest());
}
//Resolved
public static T Resolve<T>()
{
  return Container.Resolve<T>();
}


//In the code.
var Entities = IoCHelper.Resolve<Entities>();
//code
var metaData = (from user in Entities.Users where user.Id == id)

任何能给我一些帮助的人? (Ps不能仅在生产环境中重现它本地主机)

更新:它总是发生在ActionFilterAttribute中。

缓存

谢谢!

0 个答案:

没有答案