我正在使用带有node-oracledb的nodejs(在带有RHEL linux发行版的Amazon EC2实例中运行)来尝试连接到外部oracle db。但是,每当尝试建立连接时,都会出现以下错误:
Error: ORA-12162: TNS:net service name is incorrectly specified
我已经能够使用sqlplus(使用相同的连接字符串),telnet和sqldeveloper成功连接到数据库。
dbconfig.js
module.exports = {
username: 'placeholder username',
pw: 'placeholder pw',
connectionString: 'host:post/SID',
}
database.js
function simpleExecute(statement, binds = [], opts = {}) {
return new Promise(async (resolve, reject) => {
let conn;
opts.outFormat = oracledb.OBJECT;
opts.autoCommit = true;
try {
conn = await oracledb.getConnection({
user : dbConfig.username,
password : dbConfig.pw,
connectString : dbConfig.connectString
});
const result = await conn.execute(statement, binds, opts);
resolve(result);
} catch (err) {
reject(err);
} finally {
if (conn) { // conn assignment worked, need to close
try {
await conn.close();
} catch (err) {
console.log(err);
}
}
}
});
}
testdb.js
query = 'USER_ID FROM placeholder table WHERE EMAIL=:usr_id';
binds.usr_id = 'placeholder email';
result = await database.simpleExecute(query, binds);
任何人都对我为什么收到此错误有任何见解?我在网上找到的所有解决方案都没有帮助。
谢谢!
答案 0 :(得分:0)
在配置模块中,将其称为connectionString
。但是在database.js中,您引用的是connectString
。