Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2007-08-04
2
Medium Priority
?
11,316 Views
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?

example:

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

        rs.Close
'---> 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)


Thanks
0
Comment
Question by:morrisbo
2 Comments
 

Author Comment

by:morrisbo
ID: 19632657
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.

Morris
0
 
LVL 13

Accepted Solution

by:
hiteshgoldeneye earned 2000 total points
ID: 19633120
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
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

810 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