繁体   English   中英

在连接池缓存中找不到 poolAlias “default”(将 Express 服务器连接到 Oracle 数据库)

[英]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.

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