我通过以下代码使用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 access运行良好:
$ sqlplus USER/PASS@192.168.1.120/orcl
SQL*Plus: Release 11.2.0.3.0 Production on Mon Mar 12 15:18:18 2012
版权所有(c) 1982,2011,Oracle。版权所有。
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production With the Partitioning,OLAP,Data Mining and Real Application Testing options
SQL>
发布于 2012-03-13 03:16:43
connection.close(); // call this when you are done with the connection我认为这个get调用得太快了,因为所有的语句都是non-blocking in node.js(event-loop)。您可能应该将其封装在commit和rollback中的适当回调中。您还应该将所有代码包装在connection回调中
oracle.connect({ "hostname": "192.168.1.120/orcl", "user": "USER", "password": "PASS" }, function(err, connection) {
// wrap all your code inside of this.
}https://stackoverflow.com/questions/9668462
复制相似问题