Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm using node-oracle module with the following code (from the node-oracle documentation):

var oracle = require("oracle");

oracle.connect({ "hostname": "192.168.1.120/orcl", "user": "USER", "password": "PASS" }, function(err, connection) {
  if(err){ console.log("Connect err:" + err); }
  if(connection){ console.log("Connection:" + connection); }

  // selecting rows
connection.execute("SELECT nickname FROM users WHERE nickname = :1", ['luc'], function(err, results) {
  console.log("execution");
  console.log("RESULTS:" + results);
  console.log("Err:" + err);
});

connection.setAutoCommit(true);

connection.commit(function(err) {
  console.log("commiting");
  // transaction committed
});

connection.rollback(function(err) {
  console.log("rollback");
  // transaction rolledback
});

connection.close(); // call this when you are done with the connection
});

This gives me different error messages :

$ node test_node_oracle.js 
Connection:[object Connection]
rollback
commiting
execution
RESULTS:undefined
Err:Error: ORA-24324: service handle not initialized

Sometimes it also gives:

$ node test_node_oracle.js 
Connection:[object Connection]
Segmentation fault

or also:

$ node test_node_oracle.js 
Connection:[object Connection]
commiting
rollback
execution
RESULTS:undefined
Err:Error: ORA-32102: invalid OCI handle

sqlplus access works fine though:

$ sqlplus USER/[email protected]/orcl

SQL*Plus: Release 11.2.0.3.0 Production on Mon Mar 12 15:18:18 2012

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>

share|improve this question

1 Answer 1

up vote 2 down vote accepted
connection.close(); // call this when you are done with the connection

I believe this get's called too soon, because all statements are non-blocking in node.js(event-loop). You should probably wrap it in proper callback(s) inside commit and rollback. You should also wrap all your code inside of connection callback

oracle.connect({ "hostname": "192.168.1.120/orcl", "user": "USER", "password": "PASS" }, function(err, connection) {
// wrap all your code inside of this.
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.