ADO 2.5 connection problem

Dale Strickland-Clark dale at out-think.NOSPAMco.uk
Wed Jul 19 11:36:49 EDT 2000


I've just knocked up a JavaScript equivalent of this as a Windows Scripting
Component and it works a treat.

Is it me or is Python Win32Com doing something stupid?

--
Dale Strickland-Clark
Out-Think Ltd, UK
Business Technology Consultants



Dale Strickland-Clark <dale at out-think.NOSPAMco.uk> wrote in message
news:snbbe8hl1nk87 at news.supernews.com...
> Sorry about the length of this post but I've run out of ideas.
>
> The following error is produced by a short extract of the program I'm
> working on.
>
> The program opens a database connection (ADO) object which it stores in
the
> object it returns on creation.
>
> That connection is then used on subsequent calls to access record sets.
The
> test() method shows that the connection is still open.
>
> This used to work with MDAC 2.1 but I had to upgrade to MDAC 2.5. That's
> when it stopped working. This error is reproducible on NT 4.0 and Windows
> 2000.
>
> HELP! Why can't I use this connection?
>
>
> >>> import thstest
> >>> x = thstest.ths()
> Create ths...
> >>> x.logon('fred', 'pw')
> Traceback (innermost last):
>   File "<interactive input>", line 1, in ?
>   File "S:\JOBS\THS\Code\thstest.py", line 52, in logon
>     rs.open(qry, self.dbcon, adOpenStatic, adLockOptimistic, adCmdText)
>   File "d:\Program Files\Python\win32com\client\dynamic.py", line 428, in
> __getattr__
>     raise pythoncom.com_error, details
> com_error: (-2147352567, 'Exception occurred.', (0, 'ADODB.Recordset',
> 'Operation is not allowed on an object referencing a closed or invalid
> connection.', 'C:\\WINNT\\HELP\\ADO210.CHM', 0, -2146824579), None)
> >>> x.test()
> Connection state: 1
> >>>
>
>
> from win32com.client import Dispatch
>
> # Constants
>
> # ---- CursorTypeEnum Values ----
> adOpenStatic = 3
> # ---- LockTypeEnum Values ----
> adLockOptimistic = 3
> # ---- CommandTypeEnum Values ----
> adCmdText = 0X0001
>
> # ---- ObjectStateEnum Values ----
> adStateClosed = 0X00000000
> adStateOpen = 0X00000001
> adStateConnecting = 0X00000002
> adStateExecuting = 0X00000004
> adStateFetching = 0X00000008
>
> sourcedb = "s:\\data\\merlin.mdb"
>
> class ths:
>     def __init__(self):
>         self.dbcon = Dispatch("ADODB.Connection")
>         self.dbcon.Open("Driver={Microsoft Access Driver (*.MDB)}; DBQ=" +
> sourcedb)
>         print "Create ths..."
>
>     def test(self):
>         print "Connection state:", self.dbcon.state
>
>     def __del__(self):
>         print "Deleting ths..."
>         self.dbcon.Close()
>         self.dbcon = None
>
>     def logon(self, email, password):
>         rs = Dispatch("ADODB.Recordset")
>         qry = "select * from user where email = '%s' and password = '%s'"
%
> (email, password)
>         rs.open(qry, self.dbcon, adOpenStatic, adLockOptimistic,
adCmdText)
>         return not rs.EOF
>
>
>
>
> --
> Dale Strickland-Clark
> Out-Think Ltd, UK
> Business Technology Consultants
>
>
>





More information about the Python-list mailing list