[python-win32] Fw: [ pywin32-Bugs-3292681 ] adodbapi - Subtle crash

Vernon Cole vernondcole at gmail.com
Thu Apr 28 23:07:09 CEST 2011


I found two fixes for the crash.  Now I need one of you brilliant folks to
tell me which is correct. First, here is a snippet from adodbapi.
Look closely at the comments on the last three lines of code ...
v v v v v v v v v
[... Snip ...]
[   (Note: lines below are paraphrased -- not quite the actual code) ]
def connect(connection_string):
    pythoncom.CoInitialize()
    conn = win32com.client.Dispatch("ADODB.Connection")
    conn.ConnectionString = connection_string
    conn.Open()
    return Connection(conn)

class Connection(object):
    __init__(self,conn):
        self.adoConn = conn
        self.messages = []

[... snip ...]
   def _closeAdoConnection(self):                  #all v2.1 Rose
        """close the underlying ADO Connection object,
           rolling it back first if it supports transactions."""
        if self.supportsTransactions:
            self.adoConn.RollbackTrans()
        self.adoConn.Close()

    def close(self):
        self.messages=[]
        try:
            self._closeAdoConnection()                      #v2.1 Rose
        except (Exception), e:
            self._raiseConnectionError(InternalError,e)

        del self.adoConn                                       #### adding
this line cures the crash
                                                                       ####
or
        pythoncom.CoUninitialize()                        #### removing this
line cures the crash
^ ^ ^ ^ ^ ^ ^ ^ ^ ^

So --- which is the correct correction?
remove the CoUininitialize()
or perform the explicit del of the Dispatch object?
---
Vernon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20110428/2808e069/attachment.html>


More information about the python-win32 mailing list