New transaction is not allowed because there are other threads running in the session

后端 未结 4 1267
無奈伤痛
無奈伤痛 2020-12-19 05:14

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

4条回答
  •  生来不讨喜
    2020-12-19 05:53

    You don't dispose the context when your request is finished. You can dispose the context either by applying a using block ...

    using (var context = new MyContext())
    {
        // Do Db stuff and SaveChanges, etc.
    }
    // context gets disposed automatically here
    

    ... or explicitly:

    context.Dispose();
    

    (That's my theory based on your input so far.)

提交回复
热议问题