无法从 linux 环境连接到 Oracle 云自治数据库

Unable to connect to oracle cloud autonomous database from linux environment

我正在使用以 Oracle 自治数据库作为后端的 Node JS 应用程序。 它在我的本地机器上运行良好,我可以毫无问题地连接它。 我尝试将 Node JS 项目部署到 Linux 服务器上的 Azure WebAppService。

最初在部署后,我的项目无法找到 Oracle 客户端,因此经过大量搜索后,我能够通过以下方法解决该问题

steps

有了这个我就能够解决客户端问题。 我有从 oracle 收到的钱包文件,我已将其放在管理文件夹中

但现在的问题是,当我发出任何请求时,我都会收到此错误

data:{"message":"db.doConnect is not a function","stack":"TypeError: 
db.doConnect is not a `function\n`
createPool() callback: ORA-28759: failure to open file

我的代码: // 包括所有外部依赖 const oracledb = require('oracledb'); // 初始化变量 const numRows = 100; 让respArr = []; 让连接对象; 异步函数初始化(envName){

  await oracledb.createPool({
    user: process.env.DATABASEUSERNAME,
    password: process.env.DATABASEPASSWORD,
    connectString: process.env.DATABASECONNECTIONSTRING,
  });
}

async function close(poolAlias) {
  await oracledb.getPool(poolAlias).close();
}
// Function to iterate through all the rows fetched in the result set and resturn the same
async function fetchRowsFromRS(connection, resultSet, numRows) {
  // Get the rows
  try {
    const rows = await resultSet.getRows(numRows);
    // no rows, or no more rows, then close the result set
    if (rows.length === 0) {
      console.log('No rows returned');
      // doClose(connection, resultSet);
    } else if (rows.length > 0) {
      console.log(`Got ${rows.length} rows`);
      respArr = respArr.concat(rows);
      // Call the function recursively to get more rows
      await fetchRowsFromRS(connection, resultSet, numRows);
    }
    // Return the rows
    return respArr;
  } catch (err) {
    console.log(err);
  }
}

async function simpleExecute(statement, binds = [], numberOutCur, poolAlias, opts = {}) {
  try {
    await initialize();
    opts.outFormat = oracledb.OBJECT;
    opts.autoCommit = true;
  
    
    connectionObject = await oracledb.getConnection(poolAlias);
    const finalResult = {};
    const result = await connectionObject.execute(statement, binds, opts);
    let promises = [];

    for (let idx = 0; idx < numberOutCur; idx++) {
      const refCurName = `ref_cur_${idx}`;
      promises.push(fetchRowsFromRS(connectionObject, result.outBinds[refCurName], numRows));
      const resultRows = await Promise.all(promises);
      respArr = [];
      finalResult[refCurName] = resultRows;
      promises = [];
    }
    return finalResult;
    // const values = await Promise.all(promises);
    // return values;
  } catch (error) {
    return error;
  } finally {
    if (connectionObject) {
      try {
        await connectionObject.close();
      } catch (err) {
        console.log(err);
      }
    }
  }
}

// Function to release the connection
function doRelease(connection) {
  connection.close(
    (err) => {
      if (err) {
        console.log(err.message);
      }
    },
  );
}

// Function to close the result set connection
function doClose(connection, resultSet) {
  resultSet.close(
    (err) => {
      if (err) { console.log(err.message); }
      doRelease(connection);
    },
  );
}

// Export functions
module.exports.simpleExecute = simpleExecute;
module.exports.initialize = initialize;
module.exports.close = close;

我用这个调用我的过程

 const allProducts = await dbSvc.simpleExecute(query, cart_data_binds, 1, 
    'default');

我对这条消息的理解是我无法连接到我的云数据库,我不确定如何解决这个问题,任何人都可以帮助我解决这个问题已经 2 周了。

在 Node JS 项目中,我使用 simpleoracle 库连接我的 oracle 云匿名数据库

谢谢,Christopher Jones and saiharika213。将您的建议作为答案发布,以帮助其他社区成员。

这个 ORA-28759: failure to open file 错误似乎需要更新 sqlnet.ora 中的 WALLET_LOCATION 目录。可以参考Connecting to Oracle Cloud Autonomous Databases

您可以通过将连接字符串更改为指向钱包位置来解决此错误。 将钱包移动到各自的项目文件夹并修改 dbConfig.js 中的连接字符串,如下所示。 提供从根目录到钱包文件夹的钱包路径。

例如:

module.exports = {
user: username,
password:password,
connectString:"(DESCRIPTION = (ADDRESS = (PROTOCOL = TCPS)(HOST = Hostname )(PORT = XXXX))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = Servicename))(SECURITY=(MY_WALLET_DIRECTORY=/Users/yharika/Node_Projects/invoice_app/config/wallet)))"
}

可以参考Unable to connect to oracle database from node js using sqlnet.ora with oracle wallet and Connecting with TCPS - ora-28759: failure to open file