Ninject & Entity Framework =(sometimes) "The ObjectContext instance has been disposed ..."

Posted by n26 on Stack Overflow See other posts from Stack Overflow or by n26
Published on 2010-05-14T19:29:55Z Indexed on 2010/05/14 19:34 UTC
Read the original article Hit count: 1537

Filed under:
|
|
|

I am using Ninject and ADO.Net Entity Framework in my Aps.Net (Mvc) website. I bind the ObjectContext to Ninject using the RequestScope:

Bind<Entities>().ToSelf().InRequestScope().WithConstructorArgument("connectionString", _connectionString);

In most cases this works perferct. But sometimes I got the following error:

The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

This error occurs at different positions while getting, updating, inserting or deleting data. In some cases this error occurs until I reset my webapp and sometimes it disappears after some requests.

I am displeased that I have no more details. Because it seems that there is no pattern when and where this error occurs. Because the time and position is allways different :(

Some hints or ideas?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ADO.NET