执行完成ADODB连接事件未触发adAsyncExecute参数 [英] ExecuteComplete ADODB Connection event not fired with adAsyncExecute parameter

查看:334
本文介绍了执行完成ADODB连接事件未触发adAsyncExecute参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



下面我的代码VBA(在类模块中名为clsAsync):

我有一个问题,试图捕获一个存储的proc执行异步执行。 >

  Option Explicit 

私人WithEvents cnn作为ADODB.Connection


Private Sub cnn_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)
MsgBoxExecution完成
End Sub

Sub execSPAsync()
设置cnn =新建ADODB.Connection
设置rst =新建ADODB.Recordset
cnn.ConnectionString = 连接到我的数据库SQLSEREVER
cnn.Open
cnn.Executekp.sp_WaitFor,adExecuteNoRecords,adAsyncExecute
End Sub

此类是PublicNotCreatable。



要从模块调用子execSPAsync,我使用以下代码:

  Sub testASYNC()
Dim a As new clsAsync
调用a.execSPAsync
End Sub

存储过程很简单:

  alter PROC kp.sp_WaitFor 
AS

WAITFOR DELAY '00:00:05'
我的问题是ExecuteComplete事件根本没有被触发,而如果我发表了adAsynExecute参数,那么所有这些都可以正常工作。
关于如何解决我的问题的任何想法?

解决方案

我解决了我的问题,替换了调用代码:

  Sub testASYNC()
Dim a As new clsAsync
调用a.execSPAsync
End Sub

使用此新代码:

 私人a as clsAsync 

Sub testASYNC()
设置a =新的clsAsync
调用a.execSPAsync
End Sub

在异步模式下,对象a在过程结束时(范围可见性问题)不再可用。


I have a problem trying to catch the completion of a stored proc execute asynchronously.

Below my code VBA (in a class module named clsAsync):

Option Explicit

Private WithEvents cnn As ADODB.Connection


Private Sub cnn_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)
    MsgBox "Execution completed"
End Sub

Sub execSPAsync()
    Set cnn = New ADODB.Connection
    Set rst = New ADODB.Recordset
    cnn.ConnectionString = "connection to my database SQLSEREVER"
    cnn.Open
    cnn.Execute "kp.sp_WaitFor", adExecuteNoRecords, adAsyncExecute
End Sub

This class is PublicNotCreatable.

To call the sub execSPAsync from a module I use the following code:

Sub testASYNC()
    Dim a As New clsAsync
    Call a.execSPAsync
End Sub

The stored procedure is very simple:

alter PROC kp.sp_WaitFor
AS

WAITFOR DELAY '00:00:05'

My problem is that the event ExecuteComplete is not fired at all, while if I comment the adAsynExecute parameter all is working fine. Any idea on how to solve my question?

解决方案

I solved my problem replacing the calling code:

Sub testASYNC()
    Dim a As New clsAsync
    Call a.execSPAsync
End Sub

with this new code:

Private a As clsAsync

Sub testASYNC()
    Set a = New clsAsync
    Call a.execSPAsync
End Sub

In the async mode, the object "a" is no longer available at the end of the procedure (scope visibility issue).

这篇关于执行完成ADODB连接事件未触发adAsyncExecute参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆