首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ubuntu上使用node-oracle时的分段

在ubuntu上使用node-oracle时的分段
EN

Stack Overflow用户
提问于 2012-03-12 22:00:57
回答 1查看 944关注 0票数 0

我通过以下代码使用node-oracle模块(来自node-oracle文档):

代码语言:javascript
复制
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
});

这会给我不同的错误消息:

代码语言:javascript
复制
$ node test_node_oracle.js 
Connection:[object Connection]
rollback
commiting
execution
RESULTS:undefined
Err:Error: ORA-24324: service handle not initialized

有时,它还提供了:

代码语言:javascript
复制
$ node test_node_oracle.js 
Connection:[object Connection]
Segmentation fault

或者也可以:

代码语言:javascript
复制
$ 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>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-13 03:16:43

代码语言:javascript
复制
connection.close(); // call this when you are done with the connection

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

代码语言:javascript
复制
oracle.connect({ "hostname": "192.168.1.120/orcl", "user": "USER", "password": "PASS" }, function(err, connection) {
// wrap all your code inside of this.
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9668462

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档