[英]poolAlias "default" not found in the connection pool cache (Connecting Express server to Oracle database)
I'm trying to connect an Oracle database on a server, to my Express server,我正在尝试将服务器上的 Oracle 数据库连接到我的 Express 服务器,
The Express server part is OK, but when I try to start the DB, I get this error : Express 服务器部分没问题,但是当我尝试启动数据库时,出现此错误:
(node:10992) UnhandledPromiseRejectionWarning: Error: NJS-047: poolAlias "default" not found in the connection pool cache
I think the issue is when I do the "createPool" in the services/database.js file below :我认为问题是当我在下面的 services/database.js 文件中执行“createPool”时:
Here's a part of the files :这是文件的一部分:
index.js索引.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
}
config/database.js配置/数据库.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
}
};
services/database.js服务/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;
I also came accross this issue, try by defining connection pool alias poolAlias: 'hrPool' in your connection config and include pool alias when retrieving connection.我也遇到了这个问题,尝试通过在连接配置中定义连接池别名 poolAlias: 'hrPool'并在检索连接时包含池别名。 conn = await oracledb.getConnection('hrPool');
For more info https://oracle.github.io/node-oracledb/doc/api.html#getconnectionpoolalias有关更多信息https://oracle.github.io/node-oracledb/doc/api.html#getconnectionpoolalias
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.