locked
EF Context disposed incorrectly RRS feed

  • Question

  • User-1173886489 posted

    Hi All,

     

    I have a web application which uses entity framework to access data. I use one context per request's lifetime. So a context is created the first time it is requested and added to a static dicrionary with current thread's id as a key. The subsequent requests for a context retrieve it from a dictionary. When Application_EndRequest event is raised I dispose the context (current thread's id is a key to find it). Works perfectly when tested in VS build in development web server and on the testing server with iis 7 installed.

    But on another server with iis 6 the strange problems happen. Quite often I get exceptions "Database context is disposed" during the execution. Looks like the Application_EndRequest event happens before the page processing is actually finished.

    I'm not sure this is related to iis 6, it seems it becomes worse when the application is used more intensive.

    Any ideas why this happens?

     

    Many thanks,
    Artem

    Monday, February 21, 2011 1:01 PM

All replies

  • User1957418580 posted

    Can you post the full error with the stack trace?  This may be something that the database forums will have to answer, but please post the full message so that I can do a little research.  Thanks!

    Wednesday, February 23, 2011 7:11 AM