Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

PRB: Run-Time Error Message 3705 Occurs When Trying to Set the ActiveConnection Property of an ADO Recordset to Nothing


View products that this article applies to.

Symptoms

When you attempt to disconnect an ADO Recordset by setting its ActiveConnection Object property to Nothing, the following error message might appear:
Run-time error '3705': Operation is not allowed when the object is open.

↑ Back to the top


Cause

Only client-side ADO recordsets can be disconnected. The specified error occurs only when you attempt to disconnect a server-side ADO recordset.

↑ Back to the top


Resolution

Set the CursorLocation property of the ADO Recordset to adUseClient.

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


More information

Steps to Reproduce Behavior

Run 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.
  1. Open a new Standard EXE project in Visual Basic 6.0. Form1 is created by default.
  2. On the Project menu, select References, and then set a reference to the Microsoft ActiveX Data Objects 2.x Library.
  3. Add a CommandButton to Form1.
  4. 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
    
    rs.Close
    cn.Close
    
    End Sub
    					
  5. Save and run the project.
  6. 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.
  7. Stop the running of the project and add the following line of code before the cn.Open statement:
    cn.CursorLocation = adUseClient
    					
  8. Save and run the project again, and note that error message 3705 does not occur, and that the recordset gets disconnected as expected.

↑ Back to the top


Keywords: kbprb, KB275927

↑ Back to the top

Article Info
Article ID : 275927
Revision : 3
Created on : 5/8/2003
Published on : 5/8/2003
Exists online : False
Views : 417