Microsoft Knowledge Base Email Alertz

(275927) - 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. Only client-side ADO...

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 275927 - Last Review: May 8, 2003 - Revision: 2.1

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

This article was previously published under Q275927

On This Page

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.

CAUSE

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

RESOLUTION

Set the CursorLocation property of the ADO Recordset to adUseClient.

STATUS

This behavior is by design.

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.

APPLIES TO
  • Microsoft ActiveX Data Objects 2.0
  • Microsoft ActiveX Data Objects 2.1
  • Microsoft ActiveX Data Objects 2.1 Service Pack 1
  • Microsoft ActiveX Data Objects 2.1 Service Pack 2
  • Microsoft ActiveX Data Objects 2.5
  • Microsoft ActiveX Data Objects 2.6
  • Microsoft ActiveX Data Objects 2.7
  • Microsoft Data Access Components 2.0
  • Microsoft Data Access Components 2.1
  • Microsoft Data Access Components 2.1 Service Pack 1
  • Microsoft Data Access Components 2.1 Service Pack 2
  • Microsoft Data Access Components 2.5
  • Microsoft Data Access Components 2.5 Service Pack 1
  • Microsoft Data Access Components 2.6
  • Microsoft Data Access Components 2.7
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
Keywords: 
kbprb KB275927
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

nash Report As Irrelevant  
Written: 7/11/2007 12:00 AM
it's good. it's helpful for me. Thanks.....

shakir Report As Irrelevant  
Written: 3/28/2008 6:14 AM
thanks it is very helpful for me. THANKS............