Session variable timeout? - System.NullReferenceException: Objectreference not set to an instance of

M

Mel

If my website is left open on a computer for more than 20 minutes,
then the user clicks the "Save" button (to submit the form) to make
sure they save the current record before moving to another the user
gets this error.

System.NullReferenceException: Object reference not set to an instance
of an object.
It fails on this line: Dim dttd As DataTable = Session
("TaskDetDataTable")

The same code works fine if they close their browser, open the website
again, and save the record. I tried changing the session timeout in
the Home directory configuration options in IIS to 90 minutes but it
still doesn't work well, I really don't want my session variables to
EVER clear out. How can I fix my issue?
 
E

Erica

Check the session to make sure it isn't Nothing before setting dttd. Then, if
it's Nothing you can handle it accordingly.
 
G

Gregory A. Beamer

You DO want session values to timeout. Trust me on this. The problem with
setting up a "never expiring" session is you end up consuming tons of memory
for nothing. Not a wise decision.

You can solve your problem by recreating the dataset, or storing the dataset
info somewhere other than session. You can also set up the page to timeout
on the user and svae the data they walked away from in a database (but not
in the actual tables yet). When they restore session, you can bring the form
back up with the data they should have saved before going out to lunch. You
can also train users not to walk away in the middle of a form, rearchitect
with shorter form segments, etc.

But extending session to eternity is a dog just waiting to bite you in the
hindquarters.
 
M

Mel

Check the session to make sure it isn't Nothing before setting dttd. Then, if
it's Nothing you can handle it accordingly.







- Show quoted text -

The point is it just gets reset to nothing automatically after 20
minutes. It's a datatable object, so are you saying I need to
recreate the datatable if the session variable returns nothing? Where
else can I store the datatable information?
 
M

Mel

You DO want session values to timeout. Trust me on this. The problem with
setting up a "never expiring" session is you end up consuming tons of memory
for nothing. Not a wise decision.

You can solve your problem by recreating the dataset, or storing the dataset
info somewhere other than session. You can also set up the page to timeout
on the user and svae the data they walked away from in a database (but not
in the actual tables yet). When they restore session, you can bring the form
back up with the data they should have saved before going out to lunch. You
can also train users not to walk away in the middle of a form, rearchitect
with shorter form segments, etc.

But extending session to eternity is a dog just waiting to bite you in the
hindquarters.

--
Gregory A. Beamer
MVP: MCP: +I, SE, SD, DBA

Blog:http://feeds.feedburner.com/GregoryBeamer

********************************************
|   Think Outside the Box!                            |







- Show quoted text -

"or storing the dataset info somewhere other than session"
- Like where?

Maybe form was a bad choice of words, it's just a .aspx page. I don't
use Windows forms. Anyway, my datatable session variable gets reset
(my gridview is linked to the datatable) which stinks. I read the
datatable to perform the save which writes the data to an SQL Server,
obviously can't read the datatable if it's empty - I get that, but
what other alternatives do I have? Do I need to recreate the
datatable, maybe from the gridview control itself (since editing is
allowed)?
 
H

Hans Kesting

Mel explained :
I really don't want my session variables to
EVER clear out. How can I fix my issue?

The session does not end as soon as the user closes his browser or
navigates away from your site (as some people seem to think). Instead
it ends a specified time after the last request. If there was a request
within the timeout period, the countdown is reset.
"No timeout" would mean that sessions stay in memory until the server
is reset - not what you want.

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top