469,327 Members | 1,226 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

destroying recordsets

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 ?
Jul 19 '05 #1
8 2330
I *always* use rs.close: set rs = nothing

Is there a benefit to leaving out rs.close?

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"middletree" <mi********@htomail.com> wrote in message
news:ex**************@TK2MSFTNGP11.phx.gbl...
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 ?

Jul 19 '05 #2
Nope; just asking if it helped to do it, or if it was being redundant.

thanks

"Aaron Bertrand - MVP" <aa***@TRASHaspfaq.com> wrote in message
news:O#**************@TK2MSFTNGP11.phx.gbl...
I *always* use rs.close: set rs = nothing

Is there a benefit to leaving out rs.close?

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"middletree" <mi********@htomail.com> wrote in message
news:ex**************@TK2MSFTNGP11.phx.gbl...
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 ?


Jul 19 '05 #3
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
"middletree" <mi********@htomail.com> wrote in message
news:ex**************@TK2MSFTNGP11.phx.gbl...
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 ?

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

"middletree" <mi********@htomail.com> wrote in message
news:ex**************@TK2MSFTNGP11.phx.gbl...
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 ?

Jul 19 '05 #5
Conax wrote:
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

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #6
Tom B wrote:
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

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #7
> 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() ...

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
Jul 19 '05 #8
A good point gentlemen. Consider my wrist slapped.
FYI:
http://msdn.microsoft.com/library/de...script01_4.asp

shows an example, and in it they check the recordset state before closing
it.


"Aaron Bertrand [MVP]" <aa***@TRASHaspfaq.com> wrote in message
news:e8**************@TK2MSFTNGP10.phx.gbl...
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() ...

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/

Jul 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Steve Jorgensen | last post: by
2 posts views Thread by Pieter Linden | last post: by
1 post views Thread by lakshmi | last post: by
16 posts views Thread by Randy Harris | last post: by
4 posts views Thread by rdemyan via AccessMonster.com | last post: by
4 posts views Thread by Olumide | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.