destroying recordsets

M

middletree

Assuming I had a recordset set up like this:

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

is it enough to close out the code with

set rs=nothing

or is there a benefit to
rs.close
set rs=nothing ?
 
A

Aaron Bertrand - MVP

I *always* use rs.close: set rs = nothing

Is there a benefit to leaving out rs.close?
 
M

middletree

Nope; just asking if it helped to do it, or if it was being redundant.

thanks
 
C

Conax

Nowadays I never use rs.close anymore. I haven't had any problem not using
it.

I guess it's ok if you want to use it in a simple method. But if want to use
it in a more complex method that opens and closes the recordset multiple
times, you will better check to see the state of the recordset first before
calling rs.close, because if the recordset is already closed, you'll get an
error calling rs.close.

Regards
Conax
 
T

Tom B

But since you don't "open" your recordsets, you use the connection.execute
method, you don't need to close them
 
B

Bob Barrows

Conax said:
Nowadays I never use rs.close anymore. I haven't had any problem not
using it.

I guess it's ok if you want to use it in a simple method. But if want
to use it in a more complex method that opens and closes the
recordset multiple times, you will better check to see the state of
the recordset first before calling rs.close, because if the recordset
is already closed, you'll get an error calling rs.close.
Ummm - that's why you use "on error resume next" before running your cleanup
code ...

If you haven't been closing you recordsets, I submit that you've been lucky
not to have run into problems.

Bob Barrows
 
B

Bob Barrows

Tom said:
But since you don't "open" your recordsets, you use the
connection.execute method, you don't need to close them

I do anyways. There is no real good reason not to.

Bob Barrows
 
A

Aaron Bertrand [MVP]

But since you don't "open" your recordsets, you use the connection.execute
method, you don't need to close them

I believe the recordset is still opened, even if you don't do so explicitly.

If it weren't, you would get an error about invalid operation for an object
in this state, or something like that (I forget the exact error message),
when you called rs.close() ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top