I have a client that a classic ASP application generates ASP_0147 errors. The first thing I will check is that they close and free SQL / ADO resources.
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 the ADO command set ActiveConnection = Nothing closes the underlying SQL connection, or should it be explicitly closed?
There should also be a line:
objCmd.ActiveConnection = Nothing
to be:
Set objCmd.ActiveConnection = Nothing
Oddly enough, the first version does not generate an error, so I ask.
I looked at ADO for so long and my knowledge is somewhat rusty.
source
share