Microsoft KB Archive/229799

= PRB: Error 3712 with the ExecuteComplete Event =

Article ID: 229799

Article Last Modified on 8/23/2001

-

APPLIES TO


 * Microsoft ActiveX Data Objects 2.0
 * Microsoft ActiveX Data Objects 2.01
 * Microsoft ActiveX Data Objects 2.1
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 2.7
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



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
 Start a new Microsoft Visual Basic project. Form1 is created by default. Set a Project Reference to the Microsoft ActiveX Data Objects Library. Insert a command button on the form. Command1 is created by default.  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=;user id=;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 </li> Run the project. Click the Command1 command button. Note the behavior.</li></ol>

Additional query words: kbdse

Keywords: kbdatabase kbprb kbsample KB229799

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.