[python-win32] DispatchWithEvents and ADO

Mark Hammond mhammond at skippinet.com.au
Thu Mar 9 00:06:00 CET 2006


> include DispatchWithEvents both the Execute() and
> Close() methods no longer work for my Dispatch object,
> with a "Member not found" error appearing. Why does
> Execute and Close work with Dispatch by itself but not
> when DispatchWithEvents is added?
>
> What I find interesting is that both the
> ConnectComplete and ExecuteComplete functions appear
> to fire in my events class, even though my error
> appears in the Execute() statement.

In that case, it may be that ADO is expecting your events to always handle
certain methods - ie, when ADO itself tries to find an event handler you
have not implemented, it will see the DISP_E_MEMBER_NOT_FOUND error (raised
by Python, as the function doesn't exist on the object).  It may be then
returning that error back to you.

Enabling "debug mode" for event handlers is tricky - you probably could open
the makepy generated file and locate the function in the events class:


>
> We've noticed that Python can get ahead of the
> execution of the SQL statements, such as adding a new
> field and then attempting to calculate its value for
> the records before Oracle has finished created it. Is
> using DispatchWithEvents and waiting for the
> ExecuteComplete (with pythoncom.PumpWaitingMessage)
> the right solution?
>
> CODE:
> -----------------
> from win32com.client import Dispatch,
> DispatchWithEvents
>
> class clsAdoEvents:
>     def OnWillConnect(self, str, user, pw, opt, sts,
> cn):
>         pass
>     def OnConnectComplete(self, error, status,
> connection):
>         print "Connection complete"
>     def OnExecuteComplete(self, lngRecordsAffected,
> pError, adStatus, pCommand, pRecordset, pConnection):
>         print "Statement executed"
>
> objAdoConnection= Dispatch('ADODB.Connection')
> objAdoConnectionEvents=
> DispatchWithEvents(objAdoConnection, clsAdoEvents)
>
> objAdoConnection.ConnectionString =
> "Provider=MSDAORA;Password=pwd;User ID=user;Data
> Source=server"
>
> objAdoConnection.Open()
> objAdoConnection.Execute("UPDATE streams SET test=99")
> objAdoConnection.Close()
>
> del objAdoConnection
> ---------------------
>
>
> OUTPUT:
> ---------------------
> Connection complete
> Statement executed
> Traceback (most recent call last):
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
> line 310, in RunScript
>     exec codeObject in __main__.__dict__
>   File
> "C:\bposthumus\programming\Python\PythonExamples\sqlWithEvents.py",
> line 17, in ?
>     objAdoConnection.Execute("UPDATE streams SET
> test=99")
>   File
> "C:\Python24\lib\site-packages\win32com\gen_py\2A75196C-D9EB-4129-
> B803-931327F72D5Cx0x2x8.py",
> line 2064, in Execute
>     , RecordsAffected, Options)
>   File
> "C:\Python24\Lib\site-packages\win32com\client\__init__.py",
> line 446, in _ApplyTypes_
>     return self._get_good_object_(
> com_error: (-2147352567, 'Exception occurred.', (0,
> None, 'Member not found.', None, 0, -2147352573),
> None)
> --------------------
>
>
>
>
>
>
> ___________________________________________________________
> Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide
> with voicemail http://uk.messenger.yahoo.com
> _______________________________________________
> Python-win32 mailing list
> Python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>



More information about the Python-win32 mailing list