[python-win32] DispatchWithEvents and ADO
Brad Posthumus
mcgooly at yahoo.com
Thu Mar 9 17:38:17 CET 2006
--- Mark Hammond <mhammond at skippinet.com.au> wrote:
> 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.
You are absolutely right, I didn't have all of the
required event handlers set up. While debugging in
PythonWin I found withinin __init__.py the lines:
def __getattr__(self, attr):
args=self._prop_map_get_.get(attr)
"args" was producing "None" which in turn created the
error message. I checked the value of "attr" and it
was looking for "OnWillExecute". So I included that as
well as "OnDisconnect" in the event handler class and
now it works perfectly.
CODE:
----------
from win32com.client import Dispatch,
DispatchWithEvents
class clsAdoEvents:
def OnWillConnect(self, str, user, pw, opt, sts,
cn):
pass
def OnConnectComplete(self, pError, adStatus,
pConnection):
print "Connection complete"
def OnDisconnect(self, adStatus, pConnection):
print "Disconnection complete"
def OnWillExecute(self, Source, CursorType,
LockType, Options, adStatus, pCommand, pRecordset,
pConnection):
pass
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=25")
objAdoConnection.Close()
del objAdoConnection
-----------
___________________________________________________________
NEW Yahoo! Cars - sell your car and browse thousands of new and used cars online! http://uk.cars.yahoo.com/
More information about the Python-win32
mailing list