Skip to Main Content

General Development Discussions


For appeals, questions and feedback, please email

c++ occi terminate connection of running result set

Paul TokarevJan 16 2024

Hello! I am trying to develop a wrapper class (let's call it WrapperClass) for getting information from an oracle database using the occi programing interface (Version 21). I am wrapping all the occi objects (Environment, Connection, Statement, ResultSet) inside of the WrapperClass. When creating an instance of the WrapperClass I am creating the Environment and the Connection object with env = Environment::createEnvironment() and conn = env->createConnection(...) respectively. My WrapperClass has a function 'query' which allows to execute one perticular select query to the database. The query is always constant. Inside of the WrapperClass::query function I create a statement object with stmt = conn->createStatement() and then getting a result set with res = stmt->executeQuer(queryString). Then I expose the next() function in the WrapperClass to be able to iterate through the result set and functions for getting result column data (these function are not interesting in this context). The WrapperClass terminates all objects in its destructor with stmt->closeResultSet(res), conn->terminateStatement(stmt), env->terminateConnection() and finaly Environment::terminateEnvironment(env). Everything works just fine but only if the result set is completelly iterated throug thus res->status() == END_OF_FETCH. But it might happen that the result set will not be completelly walked through and the WrapperClass object will be destoyed in the middle of the result set. In this case I am getting an exception SQLException: "ORA-03127: no new operation allowed until the active operation ends" on terminating the connection with env->terminateConnection(conn). I was trying to cancel the result set with res->cancel() before closing it but it didn't help. I didn't find any other oportunity to somehow abort the query execution. So how can I close/abort the query exection and terminate the connection in such case?
Thank you.

Here is a simplified Version of the WrapperClass (I omitted error and exception handling for simplicity):

void WrapperClass::connect()
  env = Environment::createEnvironment();
  conn = env->createConnection(user, pass, connectionString);

void WrapperClass::query()
  stmt = conn->createStatement();
  result = stmt->executeQuery(constatSelectStatement);

bool WrapperClass::next()
  return result->next();

ResultClass WrapperClass::fetchResult()
  /// ... getting result from columns and creating a ResultClass object

  evn->terminateConnection(conn); // -> here I am getting an exception ORA-03127
Post Details
Added on Jan 16 2024