It is not necessary to use error trapping. Below is code that sets up three connections, and leaves them in various states. The cleanup code works regardless of whether the connection is closed, open or nothing.
I recommend you create a VBScript asp class to host the connection object, in the terminate event, free your objects.
<%
' set up three connections and leave them in various states
Dim oConn1
Dim oConn2
Dim oConn3
Dim strSQL
strSQL = "Provider=SQLOLEDB;Server=myserver;User ID=me;Password=mypass;Database=mydb;"
Set oConn1 = Server.CreateObject("ADODB.Connection")
oConn1.Open strSQL
Set oConn2 = Server.CreateObject("ADODB.Connection")
oConn2.Open strSQL
Set oConn3 = Server.CreateObject("ADODB.Connection")
oConn3.Open strSQL
' now close connection 1 and set to nothing
oConn1.Close
Set oConn1 = Nothing
' close connection 2 but dont free memory
oConn2.Close
' leave conneciton 3 active
%>
<html>
<head>
<title>Connection object detection test</title>
</head>
<body>
<%
' cleanup code for each connection is exactly the same
If Not oConn1 Is Nothing Then
Response.Write "<p>oConn1 has not been set to nothing"
If oConn1.State > 0 Then
Response.Write "<br>oConn1 is still active = " & oConn1.State
oConn1.Close
End If
Set oConn1 = Nothing
Else
Response.Write "<p>oConn1 has already been freed"
End If
If Not oConn2 Is Nothing Then
Response.Write "<p>oConn2 has not been set to nothing"
If oConn2.State > 0 Then
Response.Write "<br>oConn2 is still active = " & oConn2.State
oConn2.Close
End If
Set oConn2 = Nothing
Else
Response.Write "<p>oConn2 has already been freed"
End If
If Not oConn3 Is Nothing Then
Response.Write "<p>oConn3 has not been set to nothing"
If oConn3.State > 0 Then
Response.Write "<br>oConn3 is still active" & oConn3.State
oConn3.Close
End If
Set oConn3 = Nothing
Else
Response.Write "<p>oConn3 has already been freed"
End If
%>
</body>
</html>