If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Saving a RecordSet to a Session variable

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-03-03, 10:17
ghw0668 ghw0668 is offline
Registered User
 
Join Date: Jan 2003
Location: KC, MO
Posts: 7
Question Saving a RecordSet to a Session variable

I recently was building a search page which could return results to span multiplabe pages (i.e. Viewing Page 1 or 20). Instead of having to save my spot each time and get the Query each time the page loads, I decided to bookmark the query the first time it is opened (a bookmark for where I need to start on each page) and then save the recordset to a session variable so I will not need to requery each time.

After doing this I began to wonder if there were an performance issues or other problems with this method. I am not worried about the session timing out since it is an admin site and if it does they get booted anyway (they are authenticated w/ session variables). The site does have potential to be fairly busy during some periods but not constantly. Please let me know your thoughts and if you have any better ways of accomplishing this same result using different means (I did use a stored procedure before this).

Thanks
Reply With Quote
  #2 (permalink)  
Old 01-04-03, 04:31
Bunce Bunce is offline
Registered User
 
Join Date: Jul 2002
Location: Australia
Posts: 147
You were correct to worry!!

Never store recordsets (or objects) in session scope.

Its not threadsafe and can take up much of the servers resources.

Stick to making connections on every page, its not overly expensive at all, given the correct coding techniques.

Better yet - use Stored Procedures!!!! Get your results from the stored proc, transfer your results to an array using Getrows() or even Getsring, and quickly close the connection.

Multiple connections ACROSS pages are optimsed using Connection Pooling so you shouldn't worry about that.

Cheers,
Andrew
__________________
There have been many posts made throughout the world.
This was one of them.
Reply With Quote
  #3 (permalink)  
Old 01-06-03, 10:30
ghw0668 ghw0668 is offline
Registered User
 
Join Date: Jan 2003
Location: KC, MO
Posts: 7
First of all thanks for your reply it was very helpful. I just had one more quick question. Why would saving the object to a session variable not be threadsafe. I knew it would use a lot of server resources, but I do not understand the other part. The way I think of it, since the server creates a new session for every user that hits the page, I do not see why it would not be threadsafe?

Thanks again,
Gabe
Reply With Quote
  #4 (permalink)  
Old 01-06-03, 16:29
Bunce Bunce is offline
Registered User
 
Join Date: Jul 2002
Location: Australia
Posts: 147
This article probably explains it better than I could:
http://www.yasd.com/devaspcomp2/bonus/sessobj.htm

Cheers,
Andrew
__________________
There have been many posts made throughout the world.
This was one of them.
Reply With Quote
  #5 (permalink)  
Old 01-06-03, 16:36
ghw0668 ghw0668 is offline
Registered User
 
Join Date: Jan 2003
Location: KC, MO
Posts: 7
Thanks again for the help!

Gabe
Reply With Quote
  #6 (permalink)  
Old 01-06-03, 18:45
rnealejr rnealejr is offline
Registered User
 
Join Date: Feb 2002
Posts: 2,232
The server resource hit should be enough. This solution would not be scaleable. Only use session variables when absolutely necessary. And they should only be used for small data types. Which database are you using - some of this data may be cached on the database side so multiple queries are already optimized ? Have you looked at asp.net ?
Reply With Quote
  #7 (permalink)  
Old 01-07-03, 09:46
ghw0668 ghw0668 is offline
Registered User
 
Join Date: Jan 2003
Location: KC, MO
Posts: 7
i knew asp.net would be a solution but the client i am working for did not want to take it that far...thanks for the post i have it taken care of ... just moved it to a stored procedure.
Reply With Quote
  #8 (permalink)  
Old 01-07-03, 16:16
rnealejr rnealejr is offline
Registered User
 
Join Date: Feb 2002
Posts: 2,232
Good choice.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On