PRB: Error 3712 with the ExecuteComplete Event

ID: Q229799


The information in this article applies to:


SYMPTOMS

When you execute an ActiveX Data Object (ADO) command asynchronously, the ExecuteComplete event may generate Error 3712 as follows:

Operation has been cancelled by the user


CAUSE

The scope of the command object is private to the procedure in which it appears. This would cause the command object to be released prior to calling the ExecuteComplete event (goes out of scope).


RESOLUTION

Use a command object with a broader scope, one that would be available to the ExecuteComplete event.


STATUS

This behavior is by design.


MORE INFORMATION

The ExecuteComplete event is called after a command has finished executing, when all asynchronous phases for that operation have completed. If the asynchronous operation was successful or was aborted by the user, the adStatus parameter is set to adStatusOK. Otherwise, it would be set to adStatusErrorsOccurred if the operation failed, or was aborted by the consumer.

Steps to Reproduce Behavior

  1. Start a new Microsoft Visual Basic project. Form1 is created by default.


  2. Set a Project Reference to the Microsoft ActiveX Data Objects 2.x Library.


  3. Insert a command button on the form. Command1 is created by default.


  4. Insert the following code into the General Declaration's section of Form1:
    
    Option Explicit
    Dim WithEvents cn As ADODB.Connection
    
    Private Sub Command1_Click()
        
        Dim Cmd As New ADODB.Command
        Dim ConStr As String
            
        Set cn = New ADODB.Connection
        ConStr = "Provider=SQLOLEDB.1;Data Source=<YourServerName>;user id=<YourUserID>;Password=<YourPassword>;Initial Catalog=Pubs;"
        cn.Open ConStr
        
        With Cmd
            Set .ActiveConnection = cn
            .CommandType = adCmdText
            .CommandText = "Select * From Authors"
            .Execute , , adAsyncExecute
        End With
        
    End Sub
    
    Private Sub cn_ExecuteComplete(ByVal RecordsAffected As Long, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pCommand As ADODB.Command, ByVal pRecordset As ADODB.Recordset, ByVal pConnection As ADODB.Connection)
        
        'check for errors during the asynchronous operation
        If (adStatus = adStatusErrorsOccurred) Then
            MsgBox "Error # " & pError.Number & vbCrLf & pError.Description
        End If
        
    End Sub 


  5. Run the project. Click the Command1 command button. Note the behavior.


(c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Ammar Abuthuraya, Microsoft Corporation.

Additional query words: kbdse


Keywords          : kbADO kbDatabase kbVBp kbGrpVBDB 
Version           : WINDOWS:2.0,2.01,2.1,6.0
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: May 28, 1999