I have a customer who's Classic ASP application is generating ASP_0147 errors. The first thing I'm checking is that they're closing and releasing SQL/ADO resources timeously.
Their code has the following pattern:
Function GetXXXXRecordSet()
Set objConn = Server.CreateObject("ADODB.Connection")
With objConn
.CursorLocation = 3 ''adUseServer (default)
.ConnectionString = strConnectionString
.Open
End With
Set objCmd = Server.CreateObject("ADODB.Command")
Set objCmd.ActiveConnection = objConn
'' Build command object to call SQL stored proc, snipped for brevity
Set objRs = Server.CreateObject("ADODB.RecordSet")
objRs.Open objCmd, ,3,4 '' Cursor=adOpenStatic, Locktype=adLockBatchOptimistic
'' Return Recordset
Set GetXXXXRecordSet = objRs
If Not objCmd Is Nothing Then
objCmd.ActiveConnection = Nothing '' Should this use a Set statement?
Set objCmd = Nothing
End If
If Not ObjRs Is Nothing The Set objRs = Nothing
End Function
Does setting an ADO Command's ActiveConnection = Nothing close the underlying SQL Connection or does that have to be closed explicitly?
Also should the line:
objCmd.ActiveConnection = Nothing
be:
Set objCmd.ActiveConnection = Nothing
Oddly the first version doesn't generate an error which is why I ask.
It's been so long since I looked at ADO and my knowledge is somewhat rusty.