ADO Events with win32com

Paul Moore gustav at
Fri Jul 20 23:25:17 CEST 2001

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:

if __name__ == '__main__':

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

Is there some reason that DispatchWithEvents isn't working correctly here?

Thanks for any insight,

More information about the Python-list mailing list