Does the ADO command set ActiveConnection = Nothing closes the underlying SQL connection?

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.

+3
source share
5 answers

, ActiveConnection Nothing , , , Recordsets, ( ), ( , ).

AFAIK objConn.Close , Set objConn = Nothing

+4

ADODB RS + CONN:

objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing

: objCmd.ActiveConnection =

GL!

:

http://www.aspwebpro.com/tutorials/asp/dbconnectionclose.asp

+2

, , . , SQL Server, .

+2

VBScript . , , , , GC .

The only question is whether the ADODB.Connection descriptor frees database resources. I am 99% sure that it is. If so, simply disconnecting the Connection object from the scope will free up all associated resources.

+1
source

Yes, you are right that setting an object to nothing frees up memory using "Install" ...

Set objCmd.ActiveConnection = Nothing

Hope this helps.

0
source

Source: https://habr.com/ru/post/1735246/


All Articles