This is a migrated thread and some comments may be shown as answers.

MVC3 - SQL Server Session State

2 Answers 73 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Scott
Top achievements
Rank 2
Scott asked on 27 Feb 2012, 09:22 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Damyan Bogoev
Telerik team
answered on 28 Feb 2012, 03:42 PM

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 >>
0
Scott
Top achievements
Rank 2
answered on 10 Mar 2012, 03:06 PM
Using the HttpContext.Items collection worked much better, thanks!
Tags
General Discussions
Asked by
Scott
Top achievements
Rank 2
Answers by
Damyan Bogoev
Telerik team
Scott
Top achievements
Rank 2
Share this question
or