简体   繁体   中英

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,

The Express server part is OK, but when I try to start the DB, I get this error :

(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 :

Here's a part of the files :

index.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

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

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. conn = await oracledb.getConnection('hrPool'); For more info https://oracle.github.io/node-oracledb/doc/api.html#getconnectionpoolalias

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM