Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Accessing Session variables when using SQL Server for Session state (http://www.velocityreviews.com/forums/t116433-accessing-session-variables-when-using-sql-server-for-session-state.html)

Michael 12-30-2005 07:05 PM

Accessing Session variables when using SQL Server for Session state
 
Hi,

If I use SQL Server to store session state, whenever I call
Session["myvariable"] is there a call to SQL Server? Even if I call
Session["myvariable"] a few times in the same Web page, or even the same
code block?

I'm asking because if there is one SQL Server call every time I have
Session["myvariable"], then I should store that in a local variable, right?

Thanks,
Michael



Marina 12-30-2005 07:20 PM

Re: Accessing Session variables when using SQL Server for Session state
 
I'm fairly certain that session state is retrieved once at the beginning of
the request, and then saved back to the database when the request if
finished.

However, this is very easily tested by running a trace on the SQL server in
question and seeing when state is read/written to the database.

"Michael" <nospam@nospam.com> wrote in message
news:e1AhXRXDGHA.528@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> If I use SQL Server to store session state, whenever I call
> Session["myvariable"] is there a call to SQL Server? Even if I call
> Session["myvariable"] a few times in the same Web page, or even the same
> code block?
>
> I'm asking because if there is one SQL Server call every time I have
> Session["myvariable"], then I should store that in a local variable,
> right?
>
> Thanks,
> Michael
>




Robbe Morris [C# MVP] 12-30-2005 07:52 PM

Re: Accessing Session variables when using SQL Server for Session state
 
Once at the same time in the request cycle and saves
it (whether there were changes or not) when the response cycle
ends. It does not make a database call each time
you change a session variable.

If you are working in a web farm, this product is
far more preferrable than storing state in SQL server:

http://www.eggheadcafe.com/articles/scaleout_server.asp

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.eggheadcafe.com/forums/merit.asp





"Michael" <nospam@nospam.com> wrote in message
news:e1AhXRXDGHA.528@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> If I use SQL Server to store session state, whenever I call
> Session["myvariable"] is there a call to SQL Server? Even if I call
> Session["myvariable"] a few times in the same Web page, or even the same
> code block?
>
> I'm asking because if there is one SQL Server call every time I have
> Session["myvariable"], then I should store that in a local variable,
> right?
>
> Thanks,
> Michael
>




Jim Cheshire 12-30-2005 07:56 PM

Re: Accessing Session variables when using SQL Server for Session state
 
Michael wrote:
>
> If I use SQL Server to store session state, whenever I call
> Session["myvariable"] is there a call to SQL Server? Even if I call
> Session["myvariable"] a few times in the same Web page, or even the
> same code block?
>
> I'm asking because if there is one SQL Server call every time I have
> Session["myvariable"], then I should store that in a local variable,
> right?


We make one call on the request as long as Session state is enabled for that
page. It's worth noting that because of this, you can gain significant
performance increases by disabling Session on pages that don't use it and by
setting Session to ReadOnly on pages that have no need to write to a Session
variable.

--
Jim Cheshire
================================
Blog: http://blogs.msdn.com/jamesche

Latest entry:
Getting the PID and TID of a COM Call

Describes how to get the PID of the
dllhost process a COM call is executing
in and how to locate the thread as well.





All times are GMT. The time now is 12:24 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.