Search code examples
node.jsoracle-databaseamazon-ec2rhelnode-oracledb

Error ORA-12162 when connecting Node.js to Oracle Database


I'm using nodejs (running in an amazon EC2 instance with the RHEL linux distro) with node-oracledb to attempt to connect to an external oracle db. However, whenever I attempt to make a connection I get the following error:

Error: ORA-12162: TNS:net service name is incorrectly specified

I have been able to successfully connect to the database using sqlplus (using the same connection string), telnet, and sqldeveloper.

dbconfig.js

module.exports = {
    username: 'placeholder username',
    pw: 'placeholder pw',
    connectionString: 'host:post/SID',
}

database.js

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({
                user          : dbConfig.username,
                password      : dbConfig.pw,
                connectString : dbConfig.connectString
            });

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

testdb.js

query = 'USER_ID FROM placeholder table WHERE EMAIL=:usr_id';

binds.usr_id = 'placeholder email';

result = await database.simpleExecute(query, binds);

Anyone have any insight as to why I'm getting this error? Any solutions I've found online have not been helpful.

Thanks!


Solution

  • In your config module, you call it connectionString. But in database.js, you refer to connectString.