alternative to Session vars

  • Thread starter Thread starter Slipperman
  • Start date Start date
S

Slipperman

i was wondering if there was another way to implement session-global
variables without actually using Session vars..
for some reason i get these errors when i run my site from the server that i
dont get when i run and test it locally (w2k, IIS). i'm pretty sure i read
somewhere on the host site that use of Session vars should be limited so i
figured since i had 15 of them, maybe that is just too many. i find it hard
to believe it's my code since it works all the time locally and at least
occasionally on the server. but now after making changes related to Session
vars in my code, this one goofy error happens all the time instead of just
occasionally.
 
Well, you never told us what error you are getting.

It's not the number of session variables you are using, per se. It's the
volume of sessions you expect to receive that matter. If I only create one
session variable, but do it on a page that gets hit 1000 times an hour, then
I've got 1000 session variables in memory during the course of an hour.

You could try cookies, hidden form fields, the querystring or storing data
in a database as alternatives.
 
the persistent error that prompted this msg was due to something else and is
now fixed. the occasional error that made me suspicious of Session vars in
the first place read like this..
"object not set to instance of object" or something like that
and it always happened on a statement where i was setting a local var = some
Session var. ie:
strXmlFile = Session["XmlFile"].ToString(); (strXmlFile is an empty
string; len = 0)
again it was only occasionally and only happened when running from the
server.
the wierd thing is, on a hunch i changed the init'n of the Session vars from
this format
Session["XmlFile"] = strFile + ".xml";
to
Session.Add("XmlFile", strFile + ".xml");
and it seemed to fix the problem although i don't think i've done enough
testing to know for sure.
any ideas why this would make a difference??
 
You can't retrieve an item from Session if it doesn't exist. So:

strXmlFile = Session["XmlFile"].ToString();

would return an "Object variable not set to an instance of an object." when
you try to call .ToString and "XMLFile" doesn't exist in session yet.

This assumes that "XmlFile" is already added to session and will fail if it
isn't.
Session["XmlFile"] = strFile + ".xml";

This is what actually adds "XmlFile" and makes it ok to try to retrieve it
later.
Session.Add("XmlFile", strFile + ".xml");



Slipperman said:
the persistent error that prompted this msg was due to something else and is
now fixed. the occasional error that made me suspicious of Session vars in
the first place read like this..
"object not set to instance of object" or something like that
and it always happened on a statement where i was setting a local var = some
Session var. ie:
strXmlFile = Session["XmlFile"].ToString(); (strXmlFile is an empty
string; len = 0)
again it was only occasionally and only happened when running from the
server.
the wierd thing is, on a hunch i changed the init'n of the Session vars from
this format
Session["XmlFile"] = strFile + ".xml";
to
Session.Add("XmlFile", strFile + ".xml");
and it seemed to fix the problem although i don't think i've done enough
testing to know for sure.
any ideas why this would make a difference??


Scott M. said:
Well, you never told us what error you are getting.

It's not the number of session variables you are using, per se. It's the
volume of sessions you expect to receive that matter. If I only create one
session variable, but do it on a page that gets hit 1000 times an hour, then
I've got 1000 session variables in memory during the course of an hour.

You could try cookies, hidden form fields, the querystring or storing data
in a database as alternatives.

that
so
 
i figured it wasn't there (for whatever reason) but i think the real
question is why isn't it there (rhetorical question)? if there was something
wrong with the code, i would think it would happen all the time, not just
occasionally and not just on the server. but doing the .Add did seem to fix
it even though the

Session["XmlFile"] = strFile + ".xml";

example of how to create/set a Session var i got straight out of the Sams
ASP.Net Unleashed book (Walthers). no mention of the Add method there in
regards to creating Session vars - unless i missed something.

thanx for the info..

Scott M. said:
You can't retrieve an item from Session if it doesn't exist. So:

strXmlFile = Session["XmlFile"].ToString();

would return an "Object variable not set to an instance of an object." when
you try to call .ToString and "XMLFile" doesn't exist in session yet.

This assumes that "XmlFile" is already added to session and will fail if it
isn't.
Session["XmlFile"] = strFile + ".xml";

This is what actually adds "XmlFile" and makes it ok to try to retrieve it
later.
Session.Add("XmlFile", strFile + ".xml");



Slipperman said:
the persistent error that prompted this msg was due to something else
and
is
now fixed. the occasional error that made me suspicious of Session vars in
the first place read like this..
"object not set to instance of object" or something like that
and it always happened on a statement where i was setting a local var = some
Session var. ie:
strXmlFile = Session["XmlFile"].ToString(); (strXmlFile is an empty
string; len = 0)
again it was only occasionally and only happened when running from the
server.
the wierd thing is, on a hunch i changed the init'n of the Session vars from
this format
Session["XmlFile"] = strFile + ".xml";
to
Session.Add("XmlFile", strFile + ".xml");
and it seemed to fix the problem although i don't think i've done enough
testing to know for sure.
any ideas why this would make a difference??


Scott M. said:
Well, you never told us what error you are getting.

It's not the number of session variables you are using, per se. It's the
volume of sessions you expect to receive that matter. If I only
create
one
session variable, but do it on a page that gets hit 1000 times an
hour,
then
I've got 1000 session variables in memory during the course of an hour.

You could try cookies, hidden form fields, the querystring or storing data
in a database as alternatives.

i was wondering if there was another way to implement session-global
variables without actually using Session vars..
for some reason i get these errors when i run my site from the
server
that
i
dont get when i run and test it locally (w2k, IIS). i'm pretty sure
i
read
somewhere on the host site that use of Session vars should be
limited
so of
just
 
The code is syntaxually correct. At run-time you may or may not have data,
so it's only at run-time that you may get an error.


Slipperman said:
i figured it wasn't there (for whatever reason) but i think the real
question is why isn't it there (rhetorical question)? if there was something
wrong with the code, i would think it would happen all the time, not just
occasionally and not just on the server. but doing the .Add did seem to fix
it even though the

Session["XmlFile"] = strFile + ".xml";

example of how to create/set a Session var i got straight out of the Sams
ASP.Net Unleashed book (Walthers). no mention of the Add method there in
regards to creating Session vars - unless i missed something.

thanx for the info..

Scott M. said:
You can't retrieve an item from Session if it doesn't exist. So:

strXmlFile = Session["XmlFile"].ToString();

would return an "Object variable not set to an instance of an object." when
you try to call .ToString and "XMLFile" doesn't exist in session yet.

This assumes that "XmlFile" is already added to session and will fail if it
isn't.
Session["XmlFile"] = strFile + ".xml";

This is what actually adds "XmlFile" and makes it ok to try to retrieve it
later.
Session.Add("XmlFile", strFile + ".xml");



Slipperman said:
the persistent error that prompted this msg was due to something else
and
is
now fixed. the occasional error that made me suspicious of Session
vars
in
the first place read like this..
"object not set to instance of object" or something like that
and it always happened on a statement where i was setting a local var
=
some
Session var. ie:
strXmlFile = Session["XmlFile"].ToString(); (strXmlFile is an empty
string; len = 0)
again it was only occasionally and only happened when running from the
server.
the wierd thing is, on a hunch i changed the init'n of the Session
vars
from
this format
Session["XmlFile"] = strFile + ".xml";
to
Session.Add("XmlFile", strFile + ".xml");
and it seemed to fix the problem although i don't think i've done enough
testing to know for sure.
any ideas why this would make a difference??


Well, you never told us what error you are getting.

It's not the number of session variables you are using, per se.
It's
the
volume of sessions you expect to receive that matter. If I only create
one
session variable, but do it on a page that gets hit 1000 times an hour,
then
I've got 1000 session variables in memory during the course of an hour.

You could try cookies, hidden form fields, the querystring or
storing
data
in a database as alternatives.

i was wondering if there was another way to implement session-global
variables without actually using Session vars..
for some reason i get these errors when i run my site from the server
that
i
dont get when i run and test it locally (w2k, IIS). i'm pretty
sure
i limited
find
 
Back
Top