Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question - Recordset

Status
Not open for further replies.

Patbeau

Programmer
Apr 7, 2003
32
0
0
CA
Hi,
I would like to know, if I make a redirect before I close my recordset will it be close or let open? Is the processing of the page stopped when I do my redirection?

Ex:

IF GetUser.RecordCount > 0 then
Session("User_ID") = GetUser("Usager_ID")
Session("Group_ID") = GetUser("Parent_ID")
ELSE
Response.Redirect "index.asp?error=1"
END IF

GetUser.Close
SET GetUser = nothing

objConn.Close
SET objConn = nothing

Thank you,
patrice beauvais
 
Close the recordset and connection and set them to nothing before you do the redirect
 
Eventually the connection to the database server will be closed by the database server.

The recordset object will be dropped when the script stops, which occurs when you redirect.

But why not clean it up explicitly before you redirect. It is just good practice.

Code:
IF GetUser.RecordCount > 0 then
  Session("User_ID") = GetUser("Usager_ID")
  Session("Group_ID") = GetUser("Parent_ID")
END IF

GetUser.Close
SET GetUser = nothing

objConn.Close
SET objConn = nothing

IF GetUser.RecordCount = 0 then
  Response.Redirect "index.asp?error=1"
END IF

 
Thats what I thought. I did some test but I wanted some confirmation by pros.. :p But in your example wont it make an error if you refer to RecordCount when the recordset is closed?

Sorry for my english...
 
do u want to carry a recordset from one page to another? because as u found out response.redirect will stop execution and delete all the objects and variables....

Known is handfull, Unknown is worldfull
 
Ok so why people tell me to close the recordset if redirect close everything? Just a good programming habit?

thank you,
 
"Just a good programming habit?"

Nope, it's *must*. What happens is (VERY BASICALLY) this:
Presume that the Bold is the VB and the italics are what the system is actually doing...

Set objWhatever = New Object
system allocs a chunk of memory for the object
For whatever Loop & process
process the progam
Set whatever = Nothing
Free up the memory used by object

Now, the system SHOULD free up the memory when your routine finishes and goes out of scope, but it is not guaranteed. This means that the memory is still "marked" as used up. If you keep doing this, you'll run out of system resources. It's a memory leak.

Also, with something like a recordset, the .close method again frees up the connection to the data and the memory required.

Now if you're thousands of hits to the page that is using up all that memory, at best your server will slow down to a crawl, and at worse, crash completely.

Newer generations of MS OS's are better at handling memory than (say) the Win9x generations, but you should still be sure to free up what you've used.

I hope I've explained it well enough for you to get the gist! :)
 
Right. My code will throw an error; then I revise it.

The idea is to use the ADODB component to get data from the database; move the data into local variables as soon as possible; destroy the component; use the local variables for further processing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top