Steps to Reproduce BehaviorRun the following steps to reproduce this error message by using a Standard EXE Visual Basic 6.0 project. The sample code establishes an ADO connection to the SQL Server PUBS sample database and opens an ADO Recordset on the Authors table. You can modify the ADO connection string to connect to a database of your choice if you do not have the SQL Server PUBS sample database.
- Open a new Standard EXE project in Visual Basic 6.0. Form1 is created by default.
- On the Project menu, select References, and then set a reference to the Microsoft ActiveX Data Objects 2.x Library.
- Add a CommandButton to Form1.
- Copy and paste the following code in the form module:
Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
'Place cn.CursorLocation = adUseClient here
cn.Open "Provider=SQLOLEDB;Data Source=<SQL Server>;Initial Catalog=pubs;User Id=<UID>;Password=<PWD>"
rs.Open "Select * from authors", cn, adOpenStatic, adLockBatchOptimistic
Set rs.ActiveConnection = Nothing
- Save and run the project.
- Click the CommandButton on Form1, and note that the error message specified in the "Symptoms" section of this article appears. Clicking Debug in the error message window breaks on the Set rs.ActiveConnection = Nothing statement.
- Stop the running of the project and add the following line of code before the cn.Open statement:
cn.CursorLocation = adUseClient
- Save and run the project again, and note that error message 3705 does not occur, and that the recordset gets disconnected as expected.