shu*_*l92 2 javascript oracle oracle11g node.js npm
目前,我正在一个项目中,要求后端在中完成oracle。我使用给定的链接,并在Mac上使用npm 安装了node-oracledb。我的文件内容如下
var oracledb = require('oracledb');
oracledb.getConnection(
{
user : 'username',
password : 'password',
connectString : 'username/password//hostname:port/sid'
function(err, connection)
{
if (err) {
console.error(err.message);
return;
}else{
connection.execute(
"SELECT * from TableName",
function(err, result)
{
if (err) { console.error(err); return; }
console.log(result.rows);
});
}
});
Run Code Online (Sandbox Code Playgroud)
当我运行节点filename.js时,出现以下错误
ORA-12154: TNS:could not resolve the connect identifier specified
Run Code Online (Sandbox Code Playgroud)
我正在使用的节点版本是,v7.0.0而npm版本是v3.10.8。我的oracle数据库也是11g云上的一个实例。有人可以让我知道我在做什么错吗?
看来您的connectString是错误的,根据文档显示它只是主机名:端口/ sid
var oracledb = require('oracledb');
oracledb.getConnection(
{
user : "hr",
password : "welcome",
connectString : "hostname:port/sid"
})
.then(function(conn) {
return conn.execute(
"SELECT department_id, department_name " +
"FROM departments " +
"WHERE manager_id < :id",
[110] // bind value for :id
)
.then(function(result) {
console.log(result.rows);
return conn.close();
})
.catch(function(err) {
console.error(err);
return conn.close();
});
})
.catch(function(err) {
console.error(err);
});
Run Code Online (Sandbox Code Playgroud)
编辑:
从2019年7月起(可能是7月之前的某个时间)connectString : "hostname:port/sid"不再可以oracledb打印错误:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
相反,如此处找到的那样,您可以设置connectString为
(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = YOUR_HOST)(PORT = YOUR_PORT))(CONNECT_DATA =(SID= YOUR_SID)))使用SID连接到数据库。
因此,更新的getConnection(关于该问题)将是:
oracledb.getConnection(
{
user : "hr",
password : "welcome",
connectString : "(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = port))(CONNECT_DATA =(SID= sid)))"
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1255 次 |
| 最近记录: |