我正在背对背执行数千个查询。在少于0.01%的时间内,出现以下错误:
ERROR:root:Traceback (most recent call last):
File "xxx", line 197, in <module>
data = execute_query(username1, password1, host1, port1, service_name1, Main_SQL_DB1)
File "xxx", line 51, in execute_query
curs.close()
InterfaceError: not open
以下功能定义:
def execute_query(username, password, host, port, service_name, sql):
global connection_string, curs, conn
try:
if username is None or password is None or host is None or port is None or service_name is None or sql is None:
logging.error("Username/Password/Database details is None. Please input credentials ")
return -1
else:
connection_string = username + '/' + password + '@' + host + ':' + port + '/' + service_name
conn = cx_Oracle.connect(connection_string)
curs = conn.cursor() # create a cursor
curs.execute(sql)
result = curs.fetchall() # fetch the results all at once
return result
except cx_Oracle.DatabaseError:
logging.error( "Connection String --> " + connection_string )
logging.error( "Query --> " + sql)
raise
finally:
curs.close() ######### Generates error here <<<<<------------
conn.close()
这是因为有时无法建立Oracle连接吗? (else
中的第二行)。
任何避免这种情况的建议。
是的,我可能要做的一件事是在关闭它之前先检查它是否为OPEN,但是我需要了解为什么会发生bcoz而不执行特定查询。