[英]poolAlias "default" not found in the connection pool cache (Connecting Express server to Oracle database)
我正在嘗試將服務器上的 Oracle 數據庫連接到我的 Express 服務器,
Express 服務器部分沒問題,但是當我嘗試啟動數據庫時,出現此錯誤:
(node:10992) UnhandledPromiseRejectionWarning: Error: NJS-047: poolAlias "default" not found in the connection pool cache
我認為問題是當我在下面的 services/database.js 文件中執行“createPool”時:
這是文件的一部分:
索引.js
const dbConfig = require("./config/database.js");
const database = require("./services/database.js");
try {
console.log("Initializing database module");
await database.initialize();
} catch (err) {
console.error(err);
process.exit(1); // Non-zero failure code
}
配置/數據庫.js
require("dotenv").config();
module.exports = {
hrPool: {
user: process.env.USER,
password: process.env.PASSWORD,
connectString: process.env.CONNECTIONSTRING,
poolMin: 10,
poolMax: 10,
poolIncrement: 0
}
};
服務/database.js
const oracledb = require("oracledb");
const dbConfig = require("../config/database.js");
async function initialize() {
console.log("config ", dbConfig.hrPool);
const pool = await oracledb.createPool(dbConfig.hrPool);
}
module.exports.initialize = initialize;
async function close() {
await oracledb.getPool().close();
}
module.exports.close = close;
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();
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);
}
}
}
});
}
module.exports.simpleExecute = simpleExecute;
我也遇到了這個問題,嘗試通過在連接配置中定義連接池別名 poolAlias: 'hrPool'並在檢索連接時包含池別名。 conn = await oracledb.getConnection('hrPool');
有關更多信息https://oracle.github.io/node-oracledb/doc/api.html#getconnectionpoolalias
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.