jmhofhine
asked on
Disconnected Recordset Problem
I'm having a problem with a function I wrote. Basically what it needs to do is run a select statement on one mysql database, if it returns empty, run the same select statement on a different mysql database. The function then returns the recordset. The recordcount of the recordset is always -1. If I take out oDB.disconnect() & del oDB, it works. Do I have to close the connection and delete the db object?
def getRecordSet(conStr, sql, sysInfo):
localDb = ""
oDB = clsAdo()
if (conStr.find("config") <> -1):
localDb = sysInfo.configDbLocal
elif (conStr.find("spd") <> -1):
localDb = sysInfo.spdDbLocal
if (localDb <> ""):
if ( oDB.connect(localDb) == False ):
displayErrorMsg("getRecordSet", "smt_utility.py", "Could not connect to the Database.", 1)
oRS = oDB.getResultSet(sql)[0]
if (oRS.EOF):
oDB.Disconnect()
if ( oDB.Connect(conStr) == False ):
displayErrorMsg("getRecordSet", "smt_utility.py", "Could not connect to the Database.", 1)
oRS = oDB.getResultSet(sql)[0]
else:
if ( oDB.connect(conStr) == False ):
displayErrorMsg("getRecordSet", "smt_utility.py", "Could not connect to the Database.", 1)
oRS = oDB.getResultSet( sql )
oDB.disconnect()
del oDB
return oRS
Use the data in the recordset and close connection after that. Not closing the connection will take up some memory.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.