PRB: Error 3712 with the ExecuteComplete Event (229799)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 2.0
  • ActiveX Data Objects (ADO) 2.01
  • ActiveX Data Objects (ADO) 2.1
  • ActiveX Data Objects (ADO) 2.5
  • ActiveX Data Objects (ADO) 2.6
  • ActiveX Data Objects (ADO) 2.7
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0

This article was previously published under Q229799

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 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.

Modification Type:MajorLast Reviewed:8/23/2001
Keywords:kbDatabase kbDSupport kbprb kbSample KB229799