Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sharing same Record Set across many ASPs

Posted on 1999-07-08
2
Medium Priority
?
186 Views
Last Modified: 2013-12-25
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!
0
Comment
Question by:big_guy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Expert Comment

by:PBall
ID: 1863882
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.

0
 
LVL 1

Accepted Solution

by:
ssite earned 300 total points
ID: 1863883
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:

Page1.asp

...
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


Page2.ASP

...
Dim DBConn, DBRS

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

' close them when you're done

P.S.

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...






0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmakerā€¦
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question