I'm having difficulty understanding exactly how DispatchWithEvents operates. I need to execute SQL statements on tables in an Oracle database (using ADO) and it runs fine when using Dispatch. However when I 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. 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@python.org http://mail.python.org/mailman/listinfo/python-win32