FastRodas Posted April 26, 2004 Posted April 26, 2004 hi to all Xtremers, i have a data table in session and i want to clear it with a single button click. what i have is in global.aspx Sub Session_Start(Sender AS Object, E AS EventArgs) Dim tableCart AS DataTable Dim columnCart AS DataColumn tableCart = new DataTable("teste") columnCart = tableCart.Columns.Add("quantity",System.Type.GetType("System.String") ) columnCart = tableCart.Columns.Add("prodID",System.Type.GetType("System.String") ) columnCart = tableCart.Columns.Add("prodName",System.Type.GetType("System.String") ) columnCart = tableCart.Columns.Add( "cost",System.Type.GetType("System.Double") ) Session("tableCart") = tableCart end sub when i want to clear the the Session("tableCart") what i do is put this code again associated with a button. is there a better way to clear this session variable? thx Quote
wessamzeidan Posted April 26, 2004 Posted April 26, 2004 CType(Session("tableCart"),DataTable).Rows.Clear() Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
wessamzeidan Posted April 26, 2004 Posted April 26, 2004 you're welcomed Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
Arch4ngel Posted April 26, 2004 Posted April 26, 2004 ERROR. Watch out man. Putting an object in the object Session will lock a thread on the server. That means that if your server have 25 thread... it'll only allow 25 users. What I suggest you... is to make a static class or something like it... But If you want your server to be efficient, don't put objects in Session. I think it's called a deadlock. As an opinion... don't use object like DataTable in Session["something"]. They are made for literal values (string, int, bool, etc...) Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Administrators PlausiblyDamp Posted April 26, 2004 Administrators Posted April 26, 2004 Arch4ngel - do you have any evidence to back up the claim of only 25 users can have a session at any one time? Can't say I've ever come across this limitation but would love to be enlightened..... A session is a server side storage mechanism - it in itself doesn't have any threads it will be accessed from the calling process' thread. Certainly there are know and well documented issues about storing STA COM components in a Session but that is more of a limitiation of COM and doesn't impact the general use of sessions. Sessions can be a large memory drain if used incorrectly (by default they live for 20 minutes after a user has finished with them), but correct use of sessions and deliberately releasing objects that are no longer required can offset a lot of these problems. Given the above memory limits I personally see no problem with using sessions to pass DataSets / DataTables between pages etc. A deadlock is a condition were two threads are each trying to lock a resource already locked by the other and prevent either gaining the required resource, not really the situation described here. If threading andsession access is required then the Session object does provide a thread-safe method of accessing via it's SyncRoot property. Also static members of a class behave more like application variables and are shared between sessions - not specific to each session. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Arch4ngel Posted April 26, 2004 Posted April 26, 2004 We tryied this at school. We setted an object (a simple class derived from object) in the Session at Session_Start and we all went to the server (not all at the same time) - we were almost 80. And some of them could never reach the server. I think the message was kinda : "Server unavailable" or something like this. We were using VS.NET 2002 and IIS 5.0 (or is it 5.1) on Windows 2000 Advanced Server. Maybe I'm wrong... but if I am... I would like to know why it bust out like this. By the way... exceeding student trying to access the site couldn't ever access it. Seems like thread were locked. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Administrators PlausiblyDamp Posted April 26, 2004 Administrators Posted April 26, 2004 The people who couldn't access the server - could they access it before this was attempted? How about after the server was rebooted? What exactly did the simple class derived from object actually do and what was the code in the Session_Start? Not sure how an error of 'Server unavailable' indicates a threading issue - were there any other error messages logged? It seems a fair leap of faith to assume that a problem with clients accessing a web server is a threding problem when no error messages indicated this as being the cause or any of the code suggested involved threading. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Arch4ngel Posted April 27, 2004 Posted April 27, 2004 It was done 2 years ago. The server was working fine with no real limit of user on it. When we tried this with the Simple class ( only some functions, literal variable, and an object or two... don't remember but treat them as "object"). And there was the issue that I talked you. Remember... I didn't server it was "Server unavaillable" I said it was like it. Users couldn'T access it. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
microkarl Posted April 27, 2004 Posted April 27, 2004 Ok, Storing DataTable and DataSet in Session won't cause deadlock. However, what could happens is when there are too much memory are consumed, (60% of total memory by default) .NET Framework will automatically reset the server and thus, would cause somthing like "SERVER UNAVALIABLE". In order to prove it, you can make 5 or 6 big datatable (depends on how much RAM you have), and then store them into Session varibles and just keep adding it up, and you will see this error. (Go to Event Log to see more detail). So, to summarize it, it is okay to put DataTable and dataset into Session but JUST REMEBER TO CLEAR THEM. Quote Donald DUCK : YOU ARE FIRED!!!
Arch4ngel Posted April 27, 2004 Posted April 27, 2004 Thanks microkarl. It must be the error we've been talking about at school. Didn't remember however why I takled about thread... maybe it's only an obsession on my part (I love threads :p). Anyway... it cost too much of RAM to put big complex data structure in something as volatile as Session. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.