VB ActiveX EXE问题
建了一个ActiveX EXE来监控SQL中某个表的变化,引用ADO,类中有一个ActiveConnection属性用于获取应用程序传递来的Connection,然后在get_data方法中用ADO Command对象执行存储过程,问题就在,给类的ActiveConnection对象赋值时没问题,但在get_data中,把这个ActiveConnection赋值给执行存储过程的Command.ActiveConnection总是出错,传递过来的Connection对象是没问题的,然后我把这个ActiveX Exe修改一下成ActiveX DLL,执行起来却没问题,怎么回事?
下面是ActiveX EXE类中简化的代码(换成ActiveX DLL就没问题了)
Option ExplicitPrivate CMD As New ADODB.CommandPrivate CONN As New ADODB.ConnectionPublic Property Get ActiveConnection() As ADODB.Connection Set ActiveConnection = CONNEnd PropertyPublic Property Set ActiveConnection(vCONN As ADODB.Connection) Set CONN = vCONN Set CMD.ActiveConnection = CONNEnd PropertyPublic Sub getData() Dim TEMPCMD As New ADODB.Command On Error GoTo ErrorHand With TEMPCMD[color=#FF0000] Set .ActiveConnection = CONN[/color] '调试到这行出错 MsgBox "设置连接成功" .CommandType = 4 .CommandText = "test" .Execute End With Exit SubErrorHand: MsgBox Err.Number, Err.DescriptionEnd Sub