Sharing same Record Set across many ASPs

Hi, I'm using Visual Interdeve 6.0 to create an ASP application.  Is it possible to create ONE recordset and manipulate it (add, delete, navigate, update) through many active server pages?  I get a 'requires object' error whenever I try to reference the recordset from a page other than the one it is created.
Help is appreciated, thanks!
Who is Participating?
ssiteConnect With a Mentor Commented:
Yes it is.

All the variables you declare in an ASP page are limited to that page's scope only. That's why you got the 'requires object' because you mearly defined another variable with the same name as the first one (in the other page).

You need to use the Session object provided by the ASP framework. To do this, you must ALSO store the database object in the session, because your recordset object relied on that object. The session object is available on a per-user basis. Meaning the variables are stored in each user's session with the server. (There's also an Application object which lets you store stuff to be used through out all pages of all users simultaniously)

Here's some code for you:


Dim DBConn, DBRS

Set DBConn = Server.CreateObject("ADODB.Connection")


DBConn.Open ...

Set DBRS = Server.CreateObject("ADODB.Recordset")


DBRS.Open ... , DBConn

' now assign the objects to the session object
Set Session("DBConn") = DBConn
Set Session("DBRS") = DBRS

' DO NOT CLOSE or SET NOTHING the objects


Dim DBConn, DBRS

' read it back from the session
Set DBConn = Session("DBConn")
Set DBRS = Session("DBRS")

' close them when you're done


You might also want to close them in your Session_OnEnd event which is in the Global.asa file that was produced when you started the project.

Hope this helps...

The recordset usually exist only in the scope of the page.  Meaning if you load another page, recordset is no more.

You can however, cache recordset inside a Session variable, tho not advisable for scalability unless you have tons and tons of memory or only have very very few users.

To cache the recordset just assign it to as session and retrieve the session on another page before doing any operation on the recordset.

Initialization code:

Set Session("theRecordset") = myRS

where myRS is a valid recordset

then do:

Set myRS = Session("theRecordset")

in the pages that need to access the cached recordset.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.