【发布时间】:2021-09-17 00:18:06
【问题描述】:
我正在使用一个以 Oracle 自治数据库作为后端的 Node JS 应用程序。 它在我的本地机器上完美运行,我能够很好地连接它而没有任何问题。 我尝试将 Node JS 项目部署到 Linux 服务器上的 Azure WebAppService。
最初部署后,我的项目无法找到 Oracle 客户端,因此经过大量搜索后,我能够通过以下方式解决该问题
有了这个,我能够解决客户问题。 我有从 oracle 收到的钱包文件,这些文件已放在管理文件夹中
但现在的问题是,当我提出任何请求时,我都会收到此错误
data:{"message":"db.doConnect is not a function","stack":"TypeError:
db.doConnect is not a `function\n`
createPool() callback: ORA-28759: failure to open file
我的代码: // 包含所有外部依赖 常量 oracledb = 要求('oracledb'); // 初始化变量 常量 numRows = 100; 让 respArr = []; 让连接对象; 异步函数初始化(envName){
await oracledb.createPool({
user: process.env.DATABASEUSERNAME,
password: process.env.DATABASEPASSWORD,
connectString: process.env.DATABASECONNECTIONSTRING,
});
}
async function close(poolAlias) {
await oracledb.getPool(poolAlias).close();
}
// Function to iterate through all the rows fetched in the result set and resturn the same
async function fetchRowsFromRS(connection, resultSet, numRows) {
// Get the rows
try {
const rows = await resultSet.getRows(numRows);
// no rows, or no more rows, then close the result set
if (rows.length === 0) {
console.log('No rows returned');
// doClose(connection, resultSet);
} else if (rows.length > 0) {
console.log(`Got ${rows.length} rows`);
respArr = respArr.concat(rows);
// Call the function recursively to get more rows
await fetchRowsFromRS(connection, resultSet, numRows);
}
// Return the rows
return respArr;
} catch (err) {
console.log(err);
}
}
async function simpleExecute(statement, binds = [], numberOutCur, poolAlias, opts = {}) {
try {
await initialize();
opts.outFormat = oracledb.OBJECT;
opts.autoCommit = true;
connectionObject = await oracledb.getConnection(poolAlias);
const finalResult = {};
const result = await connectionObject.execute(statement, binds, opts);
let promises = [];
for (let idx = 0; idx < numberOutCur; idx++) {
const refCurName = `ref_cur_${idx}`;
promises.push(fetchRowsFromRS(connectionObject, result.outBinds[refCurName], numRows));
const resultRows = await Promise.all(promises);
respArr = [];
finalResult[refCurName] = resultRows;
promises = [];
}
return finalResult;
// const values = await Promise.all(promises);
// return values;
} catch (error) {
return error;
} finally {
if (connectionObject) {
try {
await connectionObject.close();
} catch (err) {
console.log(err);
}
}
}
}
// Function to release the connection
function doRelease(connection) {
connection.close(
(err) => {
if (err) {
console.log(err.message);
}
},
);
}
// Function to close the result set connection
function doClose(connection, resultSet) {
resultSet.close(
(err) => {
if (err) { console.log(err.message); }
doRelease(connection);
},
);
}
// Export functions
module.exports.simpleExecute = simpleExecute;
module.exports.initialize = initialize;
module.exports.close = close;
我用这个来调用我的procs
const allProducts = await dbSvc.simpleExecute(query, cart_data_binds, 1,
'default');
我对此消息的理解是我无法连接到我的云数据库,我不知道如何解决这个问题,任何人都可以帮助我解决这个问题已经 2 周了。
在 Node JS 项目中,我使用 simpleoracle 库来连接我的 oracle 云匿名数据库
【问题讨论】:
-
你能发布任何实际产生错误的代码吗?如果无法将其与您所做的事情联系起来,就很难评估错误消息。
-
听起来您的部署中缺少某些内容。该消息并不是真的说它无法连接。相反,它甚至无法尝试连接。不确定“simpleoracle 库”是什么,但看起来 Node 可能找不到它?显示代码,包括如何定义和配置
db,会很有帮助。 -
@pmdba 更新了我的帖子
-
@AlexPoole 更新了我的帖子
-
'ORA-28759: failure to open file' 听起来您没有更新 sqlnet.ora 中的 WALLET_LOCATION 目录。检查连接到 ADB 的 node-oracledb 文档:oracle.github.io/node-oracledb/doc/api.html#connectionadb
标签: node.js linux oracle azure-web-app-service oracle-cloud-infrastructure