Getting "new transaction is not allowed because there are other threads running in the session".
It has nothing to do with foreach loops or anything people usually have problems with in conjunction with this message.
I using a EF4 with a repositoy pattern and common context open throughout the request. Something happens, can't determine exactly what, and I get this message as soon as I try to savechanges with the context, across requests, and it only dissappears once I recycle the app pool.
Am I closing the connection? How can I tell? Am I using a fresh context for every request? Yes.
What's going on? Is there a work-around?
Edit: (context factory)
private static Dictionary<string, CoinEntities> _instances;
public static CoinEntities DefaultInstance
{
get
{
if (HttpContext.Current == null)
{ //todo: mock instead. testing.
if (!Instances.ContainsKey("_TEST"))
Instances["_TEST"] = new CoinEntities();
return Instances["_TEST"];
}
if (!Instances.ContainsKey("_DEFAULT"))
Instances["_DEFAULT"] = new CoinEntities();
return Instances["_DEFAULT"];
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…