0

我正在使用带有以下代码的 node-oracle 模块(来自 node-oracle 文档):

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
});

这给了我不同的错误信息:

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

有时它还给出:

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

或者也:

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

sqlplus 访问虽然工作正常:

$ sqlplus USER/PASS@192.168.1.120/orcl

SQL*Plus:2012 年 3 月 12 日星期一 15:18:18 发布 11.2.0.3.0 生产版

版权所有 (c) 1982, 2011, Oracle。版权所有。

连接到:Oracle 数据库 11g 企业版 11.2.0.1.0 版 - 具有分区、OLAP、数据挖掘和真正应用测试选项的生产

SQL>

4

1 回答 1

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

我相信这个 get 调用得太快了,因为node.js(event-loop) 中的所有语句都是非阻塞的。您可能应该将其包装在适当的回调中commitrollback. 您还应该将所有代码包装在connection回调中

oracle.connect({ "hostname": "192.168.1.120/orcl", "user": "USER", "password": "PASS" }, function(err, connection) {
// wrap all your code inside of this.
}
于 2012-03-12T19:16:43.080 回答