I want to start a function, stored in the database, from a python-script, using cx_Oracle. I re-used parts from the developer that worked with us a couple of years ago. Sometimes it functions like it should, and sometime it does'nt, I get the message “cx_Oracle.DatabaseError: DPI-1002: invalid dpiConn handle”. After calling the function succesfully the command db.close() executes without error, but when calling the function results in aforementioned error, the db.close() replies with cx_Oracle.InterfaceError: not connected. As if sometimes the connection was closed before the script was able to execute the function-calling statement.
I wil not show the complete python-script and modules. But shown below is the python-commandline session in which you can see what is happening.
$ python
Python 3.6.8 (default, Oct 2 2023, 21:12:58)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, cx_Oracle
>>> from os import path
>>> class Database:
... conn=None
... cursor=None
... DB_SERVER_HOST=""
... DB_SERVER_PORT=1521
... DB_SERVICE = ""
... DB_USERNAME = ""
... DB_PASSWORD = ""
... def __init__(self, host, service, user, pwd, threadoption=False):
... if Database.conn is None:
... Database.conn=self.getconnection(host, service, user, pwd, threadoption)
... if Database.cursor is None:
... Database.cursor=cx_Oracle.Cursor(Database.conn)
... def getconnection(self, host, service, user, pwd, threadoption):
... self.DB_SERVER_HOST=host
... self.DB_SERVER_PORT=1521
... self.DB_SERVICE = service
... self.DB_USERNAME = user
... self.DB_PASSWORD = pwd
... dsn = cx_Oracle.makedsn(self.DB_SERVER_HOST, self.DB_SERVER_PORT, service_name=self.DB_SERVICE)
... return cx_Oracle.connect(self.DB_USERNAME, self.DB_PASSWORD, dsn, threaded=threadoption)
... def getcursor(self):
... return cx_Oracle.Cursor(Database.conn)
... def commit(self):
... Database.conn.commit()
... def close(self):
... Database.conn.close()
...
>>> conndata = ['xxxxx.nl', '<db-name>', '<user-name>', '<pwd>']
>>> db = Database(conndata[0], conndata[1], conndata[2], conndata[3])
>>> cursor = db.getcursor()
>>> params = [ "updateDBnivo", "0", None, "20231204160700", "debug", "start proces", None, None, None, None, None, None ]
>>> rc = int(cursor.callfunc("glk_logutil.add_log", cx_Oracle.DB_TYPE_BINARY_INTEGER, params))
>>> db.close()
>>> rc
0
>>> db = Database(conndata[0], conndata[1], conndata[2], conndata[3])
>>> cursor = db.getcursor()
>>> params = [ "updateDBnivo", "0", None, "20231204160700", "debug", "start proces", None, None, None, None, None, None ]
>>> rc = int(cursor.callfunc("glk_logutil.add_log", cx_Oracle.DB_TYPE_BINARY_INTEGER, params))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cx_Oracle.DatabaseError: DPI-1002: invalid dpiConn handle
>>> db.close()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 29, in close
cx_Oracle.InterfaceError: not connected
>>>