C# .NET - ASP.NET Session state and DataSet object
Asked By Paul Borchardt on 12-Nov-03 11:10 AM
We are trying to save a DataSet in Session (eg. Using statement "Session[vsDataSetToken] = vdsDataSet.Copy()"). It seems to be saved ok to session when I debug through... but it seems to be null when I retrieve it from session (eg. Using "dsDataSet = (DataSet)Session[_msDATASET_TOKEN];"). My config file has settings "<sessionState mode="InProc" cookieless="false" timeout="20" />". Does anyone have any ideas why the dataset is coming out null? This seemed to work a week or more ago... so it could be that something got changed and I have overlooked something. Thank you
Session variable names in your sample arent same:
Asked By Peter Bromberg on 12-Nov-03 11:52 AM
[vsDataSetToken] = vdsDataSet.Copy()")
Using dsDataSet = (DataSet)Session[_msDATASET_TOKEN];")
--- Should be
dsDataSet = (DataSet)Session["vsDataSetToken"];
that's where you stored it, right? So that's where you need to go to get it back.
Sorry... variable names were the same
Asked By Paul Borchardt on 12-Nov-03 12:48 PM
Sorry Mr.Bromberg... I should have included the calling statement which was "SetData(dsDataSet, _msDATASET_TOKEN);". So the variables do turn out to have the same literal values when I debug thru and do a watch. But subsequent postback returns null after dataset assignment to session variable. Thanks
Paul
OK Look:
Asked By Dexter Dotnetsky on 12-Nov-03 07:11 PM
If you do this:
Session["ds"]=myDataSet;
and you are SURE the above line has executed, then you should be able to do this:
DataSet myNewDataSet =(DataSet)Session["ds"];
anywhere else (even before a postback) and get back a live version of your original Dataset in the myNewDataSet variable.
Really, its that simple.
Sounds simple but...
Asked By Paul Borchardt on 13-Nov-03 10:33 AM
My code has the lines as specified by Dr.DotNetsky except that I instantiate the dataset and assign it to (DataSet)Session["ds"] in two different statements.
What I have found since my original post is that my code works fine with session state on our development server and, after restarting IIS (which I did for another reason), it works fine on my local machine!
".Net result"... restarting IIS fixes this situation BUT it definitely was not working prior to restart of IIS. I debugged thru maybe a dozen times with slight variations and it did not get the dataset from session state.
Any thoughts greatly appreciated!
Doesn't make any sense to me
Asked By Peter Bromberg on 13-Nov-03 12:29 PM
But if restarting IIS fixes it, think about what restarting IIS is doing.
It's reloading a new ASPNET worker process, and its reloading and parsing the machine.config file, and also your web.config file for your IIS application.
You aren't using StateServer or Sql Server sessions, and you arent' using cookieless. Anybody got a clue to help this guy out?
I think I got it
Asked By Paul Borchardt on 25-Nov-03 12:47 PM
I think restarting IIS may have been misleading... I thought it worked but then again it did not seem to work consistently. It now seems that the browser setting "Empty Temporary Internet Files folder when browser is closed" (ie. in Tools > Internet Options... > Advanced tab) caused this problem when checked ON. I can consistently cause the problem by clicking it on (ie. dataset in session disappears)... and I can consistently fix the problem by clicking if off (ie. dataset in session works correctly). So I guess (some?) session is stored in temporary files (remember, I am running this locally on my own machine) and on a browser window close or even postback, a dataset in session state is lost. If someone wants to confirm and/or explain this more technically, that would be fine with me. Thanks
Pulling out my hair
Asked By Brandon Miller on 12-Jan-05 04:38 PM
Thank you so much for finding that "quirk"... I have been trying to store objects in Session for almost a year now and have been having the same issues. I've searched high and low for a resolution or even a reason and, until now, have come up with nothing!
Have you found any workaround or fix for this issue?