ADO Events with win32com
angusm
nmack at pacbell.net
Sat Jul 21 10:40:17 EDT 2001
I think the problem is that COM (or ADO?)requires you to define all
the event handlers for the interface in your class:
"All the event handlers in the ConnectionEvent ... must be
implemented, regardless of whether you actually use events. " MSDN
that is, if you use one you have to define the rest (though presumably
you can bet by with a "pass" implementation). The same goes for
Recordset events.
The ADO type library generated by makepy has the prototypes you need.
Angus
Paul Moore <gustav at morpheus.demon.co.uk> wrote in message news:<vv7hlt8dqss6e3vv2m5pko2tq94obt99r2 at 4ax.com>...
> I'm trying to get ADO events working with win32com, but I'm not getting
> anywhere. The following is my test code:
>
> -------------------------------------------------------------
> import win32com.client
>
> finished = 0
>
> class ADOEvents:
> def OnConnectComplete(*args):
> print `args`
> finished = 1
>
> def Test():
> # Conn = win32com.client.Dispatch("ADODB.Connection")
> Conn = win32com.client.DispatchWithEvents("ADODB.Connection", ADOEvents)
> ConnStr = "Provider=msdaora;Prompt=complete"
> Conn.Open(ConnStr, Options=16)
> while not finished:
> pass
>
> if __name__ == '__main__':
> Test()
> -------------------------------------------------------------
>
> If I understand things correctly, this is about what is needed.
>
> The problem is that this code immediately returns an error - 'Operation has been
> cancelled by the user'. But I didn't! I didn't even get the chance, as the login
> box did not appear.
>
> If I comment out the DispatchWithEvents call, and replace it with a straight
> Dispatch call, as on the line above, everything works as I want - the login box
> appears (although clearly the event doesn't get fired, so I get an infinite
> loop...)
>
> Is there some reason that DispatchWithEvents isn't working correctly here?
>
> Thanks for any insight,
> Paul.
More information about the Python-list
mailing list