MVC3 - SQL Server Session State

3 posts, 1 answers
  1. Scott
    Scott avatar
    68 posts
    Member since:
    Nov 2011

    Posted 27 Feb 2012 Link to this post

    Per the MVC example given for best practices for OpenAccess, we are implementing the ContextModule, and thus upon each request, creating the database context and storing it in the Session State.

    Is it possible to store OpenAccess context objects in the SQL Server Session State, and if so, how do we accomplish this?
  2. Answer
    Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 28 Feb 2012 Link to this post

    Hi Scott,

    Storing the OpenAccessContext instance in the session state could lead to wrong behavior if there are multiple requests to a page or custom handlers which are using the same session. This could lead to a situation when one request disposes the context before other request are finished doing their work, which will cause an exception. Problems could arise when the application is being used in a web farm.

    Better approach is to store the context in the HttpContext.Items collection. You could find the sample application, shipped with the Product SDK, helpful. They demonstrate how to handle the context.

    Hope that helps.

    Kind regards,
    Damyan Bogoev
    the Telerik team
    Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
  3. DevCraft banner
  4. Scott
    Scott avatar
    68 posts
    Member since:
    Nov 2011

    Posted 10 Mar 2012 Link to this post

    Using the HttpContext.Items collection worked much better, thanks!
Back to Top