Reputation: 71
My Oracle client version is 19.20.0.0.0 & node oracledb version 6.1.0
I'm running node js application randoml getting Error: NJS-040, to make connection i use pool method and made a middleware to connect...
const oracledb = require('oracledb');
const logger = require('../logger');
const { PASSWORD, USERNAME, CONN_STRING } = require('../constant');
oracledb.initOracleClient();
oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;
async function initializeOraclePool() {
try {
await oracledb.createPool({
user: USERNAME,
password: PASSWORD,
connectionString: CONN_STRING,
poolMax: 8,
poolMin: 1,
poolTimeout: 2000000,
});
logger.info(`Oracle client version is ${oracledb.oracleClientVersionString}`)
} catch (error) {
logger.error(error)
console.error('Error creating Oracle connection pool:', error);
}
}
// Middleware to acquire a database connection from the pool
async function getOracleConnection(req, res, next) {
try {
req.connection = await oracledb.getConnection();
next();
} catch (error) {
console.error('Error acquiring Oracle connection:', error);
logger.error(error)
res.status(500).json({ error: 'Database connection error' });
}
}
module.exports = { initializeOraclePool, getOracleConnection };
and I use like this
const fetchSupplierRecommendation = async (req, res) => {
try {
const { connection = {}, body = {}, query = {}, params = {} } = req;
let { planId, srInstanceId, categorySetId, from, to } = query
const result = await connection.execute(SQLQuery.SupplierRecommendation(planId, srInstanceId, categorySetId, from, to))
successHandler(res, result.rows)
} catch (error) {
errorHandler(res, error)
}
}
when I check logs I get only this error
0|index | Error acquiring Oracle connection: Error: NJS-040: connection request timeout. Request exceeded "queueTimeout" of 60000
0|index | at Object.throwErr (/var/node/node_modules/oracledb/lib/errors.js:588:10)
0|index | at Timeout._onTimeout (/var/node/node_modules/oracledb/lib/pool.js:443:22)
0|index | at listOnTimeout (node:internal/timers:569:17)
0|index | at process.processTimers (node:internal/timers:512:7) {
0|index | code: 'NJS-040'
0|index | }
Upvotes: 0
Views: 723