Home All Groups Group Topic Archive Search About

SQLServer State - how do you use it?

Author
19 Mar 2005 5:31 PM
Mark

Hi - I am regularly losing session information, I think due to the
worker process recycling.  I have been traditionally using InProc
procedures, and using them like:

Session("username")=objDR("username") 'read from database

...and then simply referencing this on any other pages code behind, as:
if Session("username")=.....

If the proces recycles while a customer is browsing, I lose all their
information (sort of web cart), they have chosen so far.

So, will changing to SQLServer state stop this?

Can I use SQLServer state with MSDE?

Do I have to make any fundamental changes to the way I read and declare
session variables? (ie. I keep hearing about serialization - does this
change the way I use the sessions, as above)?

I am using a single web server (MS 2003 Web Edition), with MSDE, and
512MB Ram.

I've changed a local version of my app, to use SQLServer State (please
see my local web.config below) - and it APPEARS to work ok, but because
I've made no change to the way I use the sessions, are they still using
the old way of working - ie. are the sessions still being stored in the
web server memory?

Sorry for my ignorance, but I really want to learn best practice.

Thanks, Mark

Web.config:

<sessionState mode="SQLServer"        sqlConnectionString="data
source=127.0.0.1;user id='sa';password=''" cookieless="false"
timeout="20"
/>

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Author
19 Mar 2005 6:00 PM
Brock Allen
> So, will changing to SQLServer state stop this?

Yes, as long as your SqlServer doesn't shutdown.

> Can I use SQLServer state with MSDE?

Yes.

> Do I have to make any fundamental changes to the way I read and
> declare session variables? (ie. I keep hearing about serialization -
> does this change the way I use the sessions, as above)?

No, as long as any custom objects you put into the session state are marked
with the Serializable attribute:

[Serializable]
public class ShoppingCart
{
    // sutff....
}

> I've changed a local version of my app, to use SQLServer State (please
> see my local web.config below) - and it APPEARS to work ok, but
> because I've made no change to the way I use the sessions, are they
> still using the old way of working - ie. are the sessions still being
> stored in the web server memory?

Yes your session state is in memory, but it's for the duration of the request.
When the request arrives in your application ASP.NET must contact the StateServer
or SqlServer to load your session state, then once the request is done (your
page) ASP.NET must store the session state back out to the StateServer or
SqlServer. So, the tradeoff is the roundtrips to the out of proc store. If
it's on the same machine, then this is not a major perf concern.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Are all your drivers up to date? click for free checkup

Author
19 Mar 2005 6:36 PM
Mark
Hi Brock - thank you very much.

I'm not very experienced - and so the objects I use are not in a class,
just things like:

session("cart")=ds 'dataset
sesion("username")=objdr("username") 'string

Do you know if a dataset is serializable - can I continue to work in
this way, without haveing to find out how to create and work with
classes (although I appreciate this is probably best practice - and I
will do it).

Thanks again.

Mark



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Bookmark and Share