Search code examples
node.jslinuxoracle-databaseazure-web-app-serviceoracle-cloud-infrastructure

Unable to connect to oracle cloud autonomous database from linux environment


I am using a Node JS application that has Oracle Autonomous Database as a backend. It works perfectly on my local machine and I am able to connect it well without any issue. I tried deploying Node JS project to Azure WebAppService on Linux server.

Initially after deployment I my project was not able to find the Oracle client and so after searching a lot I was able to fix that problem by below

steps

with this I was able to solve client issue. I have wallet files which I received from oracle which I have placed in admin folder

but now the problem is when I make any request I am getting this error

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

my code: // Include all external dependencies const oracledb = require('oracledb'); // Intialize variables const numRows = 100; let respArr = []; let connectionObject; async function initialize(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;

I call my procs using this

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

what I understood with this message is I am not able to connect to my cloud database and I am not sure how to solve this can anyone help me with it its been 2 weeks now with this problem.

In Node JS project I am using simpleoracle library to connect my oracle cloud anonymous database


Solution

  • Thank you, Christopher Jones and saiharika213. Posting your suggestions as an answer to help other community members.

    This ORA-28759: failure to open file error seems you need to update the WALLET_LOCATION directory in sqlnet.ora. You can refer to Connecting to Oracle Cloud Autonomous Databases

    You can resolve this error by changing the connection string to point to the wallet location. Move the wallets to respective project folder and modify the connection string as below in dbConfig.js. Provide the wallet path from root till wallet folder.

    For example:

    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)))"
    }
    

    You can refer to 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