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"