VB6 ADO - Proper use of recordset state property and connection state

Posted on 2007-08-04
Last Modified: 2013-12-25
In VB6 using ADO, do you get an error message if you try to close a recordset that is not open?


       Dim cn As ADODB.Connection, rs As ADODB.Recordset
       Set cn = New ADODB.Connection
       Set rs = New ADODB.Recordset

'---> later in same procedure   rs.Close  

      Set rs = Nothing

i.e. is it necessary to use the  If  rs.state = adStateOpen then rs.close  ??

 Also, what happens if I try to close a connection to an access mdb (ado) that is not open?

example --->       Call CloseDBConnection(cn)

Question by:morrisbo

    Author Comment

    Also, I forgot to ask earlier, does setting the connection to nothing close the data base?
    example ---> set cn = nothing

    Also, is the term " close the connection " the same thing as " close the data base " assuming there are no other open connections.

    LVL 13

    Accepted Solution

    Yes you get errors when you try to close a recordset or connection when it is already closed.
    You get a run time error '3704' Operation not allowed when the object is closed

    Setting cn = nothing closes the connection

    yes closing the connection closes the database for the application

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now