Click to See Complete Forum and Search --> : How to Close All Active Connections of ADO?


vipulsk
February 17th, 2000, 11:41 PM
Sir,
As I am regular user of your site and presently working with Visual Basic I am making application in VB and Oracle and I have got one problem in that. i am using ADODB for making connection in my application i have got multiple ADODB connection in my application but the problem is when sometimes abnormal termination of my program occurs it do not close the active connection with Oracle and that is why I am having problem with Oracle as well as windows. So i would like to know how can i close all my active connection on form Unload event?? or any such event regardless of connection name. Hoping to get reply soon.
Thanking you in anticipation,
Vipul.

sriky
February 18th, 2000, 07:33 AM
did you use

rs.close
set rs=nothing

cn.close
set cn=nothing




rs and cn represent recordset and connection object. you have to close all the recordsets and conn. objetcs

Kyle Burns
February 18th, 2000, 07:49 AM
If you're working with multiple connections and want to refer to them as a group, take a llok at adding them to a collection.

private m_colConns as Collection
'...Somewhere in your code
m_colConns.Add cnMyConnection
'...Now in your unload event
If Not m_colConns is nothing then
Dim cn 'you want a variant here
for Each cn in m_colConns
cn.Close
set cn = nothing
next cn
End If



You're better off to check each one individually, though. Since this is to deal with the exception, make sure you check each object to see if it still exists before trying to close it and set it to nothing or else you'll get a nastygram!

Spectre
February 20th, 2000, 12:58 AM
The code presented by the previous two posts - while correct - will cause an error if one of the connections has been closed previously by the program. If you close your connections like this it will avoid the problem:


If cnConnection.State = adStateOpen then
cnConnection.Close
End If
set cnConnection = nothing