'Oracle Database connection failed with Node Js - getting error target host or object does not exist

When i connect oracle database with Node Js got this error - Connect failed because target host or object does not exist

Error log

[Error: ORA-12545: Connect failed because target host or object does not exist] {
  errorNum: 12545,
  offset: 0
}

My Node Js Code

var oracledb = require('oracledb');

(async function() {
    let connection;
    try{
        connection = await oracledb.getConnection({
            user : 'USERNAME',
            password : 'PASSWORD',
            connectString : 'MYIP:SID'
        });
        
        var result = await connection.execute(`SELECT * FROM customeraccounts`, [],
        { resultSet: true, outFormat: oracledb.OUT_FORMAT_OBJECT });

        const rs = result.resultSet;
        console.log('rs', rs)

        console.log("Successfully connected to Oracle DB!")
    } catch(err) {
        console.log("connection err -  ", err);
    }
})()

Package.json - oracledb

Included this line

bashrc - export LD_LIBRARY_PATH=/home/ubuntu/instantclient_12_2:$LD_LIBRARY_PATH

Included this lib

Path : \home\ubuntu\instantclient_12_2

instantclient-basic-linux.x64-12.2.0.1.0.zip



Solution 1:[1]

Your client cannot resolve the server hostname or IP Address, most likely because of a typo.

12545, 00000, "Connect failed because target host or object does not exist"

// *Cause: The address specified is not valid, or the program being connected to does not exist.

// *Action: Ensure the ADDRESS parameters have been entered correctly; the most likely incorrect parameter is the node name. Ensure that the executable for the server exists (perhaps "oracle" is missing.) If the protocol is TCP/IP, edit the TNSNAMES.ORA file to change the host name to a numeric IP address and try again.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pmdba