By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,837 Members | 1,842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,837 IT Pros & Developers. It's quick & easy.

.Close, = Nothing - Real dumb question? with a real quick answer...

P: n/a
Hi, I feel a little dumb for asking this (considering im writing
TSQL) but there doesn't seem to be any definitive answers on the
search engines...

Okay I understand that if you open the ADO connection that you
close it with:

adoCon.Close
Set adoCon = Nothing

and if you open a recordset like below:

Set rsBlockedCheck = Server.CreateObject("ADODB.Recordset")
strSQL = "EXECUTE pmUserIsBlocked @lngLoggedInUserID = " &
lngLoggedInUserID &", @lngToUserID = " & lngToUserID
rsBlockedCheck.Open strSQL, strCon

you close it with...

rsBlockedCheck.Close
Set rsBlockedCheck = Nothing

My question is do you need to close and set nothing to the
strSQL like:

strSQL.Close
Set strSQL = Nothing

Personally, i'd go for you don't and that only the connection
and the recordset need closed... is this right? and - are the
.close required for the connection and recordset or do you just
set the = Nothing ?

Regards

----------------------------------------------
Posted with NewsLeecher v2.0 Beta 5
* Binary Usenet Leeching Made Easy
* http://www.newsleecher.com/?usenet
----------------------------------------------

Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
InvisibleMan wrote:
Hi, I feel a little dumb for asking this (considering im writing
TSQL) but there doesn't seem to be any definitive answers on the
search engines...

Okay I understand that if you open the ADO connection that you
close it with:

adoCon.Close
Set adoCon = Nothing

and if you open a recordset like below:

Set rsBlockedCheck = Server.CreateObject("ADODB.Recordset")
strSQL = "EXECUTE pmUserIsBlocked @lngLoggedInUserID = " &
lngLoggedInUserID &", @lngToUserID = " & lngToUserID
rsBlockedCheck.Open strSQL, strCon

you close it with...

rsBlockedCheck.Close
Set rsBlockedCheck = Nothing

My question is do you need to close and set nothing to the
strSQL like:

strSQL.Close
Set strSQL = Nothing
No. strSQL is not an object. Only oblject variables created using the Set
keyword can be set to Nothing. Not all objects provide a Close method, but
when they do, it should be used.

Personally, i'd go for you don't and that only the connection
and the recordset need closed... is this right?
right
and - are the
close required for the connection and recordset or do you just
set the = Nothing ?

both.

Using Close allows the objects to release resources they use gracefully,
eliminating references to other objects you wish to close and destroy.

---------------------------------------------------------------------------------------------------
Personally, I would not use a connection string to open your recordset
(doing so can turn off connection pooling, which can create performance
problems if you're lucky, server crashes if you're not lucky). Instead,
create an explicit connection object which you use for all data access on
the page.

Set cn = server.createobject("adodb.connection")
cn.open strCon

'open a no-default recordset
Set rsBlockedCheck = Server.CreateObject("ADODB.Recordset")
rsBlockedCheck.CursorLocation=adUseClient
rsBlockedCheck.Open strSQL, cn,,,1

'or open the default cursor like this:
set rs=cn.Execute(strSQL,,1) 'CreateObject is not necessary
'always tell ADO the command type: 1 = adCmdText

Close and destroy the connection as soon as you are finished using it, in
order to release the connection to the pool for another thread on your
server to use

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 22 '05 #2

P: n/a
Thanks Bob that was really help in more ways than one...
Much appreciated - thanks for taking the time

----------------------------------------------
Posted with NewsLeecher v2.0 Beta 5
* Binary Usenet Leeching Made Easy
* http://www.newsleecher.com/?usenet
----------------------------------------------

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.