Forum Discussion

Ryu's avatar
Ryu
Contributor
6 years ago

Connection to DB not closing properly?

I have this function that accesses a database using ADODriver.  I have it closing the connection at the end, and the first run through the function when I open TC passes.  However, on a subsequent run, TestComplete will crash because the connection is still open.  I'm not sure what I am missing.  Can anyone help?  I did notice, as I got to "countTable.ADOConnectionObject." that the auto-extension table didn't display for me to choose the Close() property, so I did type that manually.

def getTableValues():
num = []
countTable = DDT.ADODriver(ConStr, query) while not countTable.EOF(): num.append(countTable.Value[1]) countTable.Next() for i in num: Log.Message(i) countTable.ADOConnectionObject.Close()

1 Reply

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    A better way of closing it is to actually close the DDT driver.  This is a more complete way.  I'm not fully familiar with Python syntax but this is what it should look like.

     

    def getTableValues():
      num = []
      countTable = DDT.ADODriver(ConStr, query)
      while not countTable.EOF():
        num.append(countTable.Value[1])
        countTable.Next()
      for i in num:
        Log.Message(i)
      DDT.CloseDriver(countTable.Name)