[DB-SIG] ADO database connection seems to be closing
Chris Curvey
ccurvey at earthlink.net
Thu Mar 3 17:22:09 CET 2005
I'm trying to get to an MS-SQL datbase via the win32com.client library
and the ADO library, but I seem to lose the context of the connection
whenever I execute a statement. For example, the first "assert" below
is OK, but the second one is not. I'm also losing the value of @@identity.
Is this a known issue? I was hoping for a DB-API 2.0 interface to
MS-SQL, but I can't get my clients to pay for an mxODBC license.
import unittest
from win32com.client import Dispatch
class TransactionTest(unittest.TestCase):
def testConnection(self):
conn = Dispatch('ADODB.Connection')
conn.Open("Driver={SQL
Server};Server=mxdev;UID=chris_dev;PWD=chris;DATABASE=tempdb")
# start a transaction
conn.execute("begin tran")
result = conn.execute("select @@trancount")
while not result.EOF:
# this test passes
assert result.Fields.Item(0).Value == 1
result.MoveNext()
result = conn.execute("select @@trancount")
while not result.EOF:
#this test fails
assert result.Fields.Item(0).Value == 1
result.MoveNext()
########################################################################
if __name__ == "__main__":
unittest.main()
More information about the DB-SIG
mailing list