CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2000
    Posts
    4

    How to Close All Active Connections of ADO?

    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.



  2. #2
    Join Date
    Jul 1999
    Location
    USA
    Posts
    101

    Re: How to Close All Active Connections of ADO?

    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


  3. #3
    Join Date
    Feb 2000
    Location
    Indiana
    Posts
    308

    Re: How to Close All Active Connections of ADO?

    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!


  4. #4
    Join Date
    Feb 2000
    Posts
    137

    Re: How to Close All Active Connections of ADO?

    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





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured