Ask a Question

Connection to DB not closing properly?

Ryu
Contributor

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 1
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)

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
cancel
Showing results for 
Search instead for 
Did you mean: