Unable to connect oracle db with nodejs

1k views Asked by At

I tried to connect oracle DB with nodejs, and I got the message as below:

ORA-12560: TNS:protocol adapter error

This is my code:

oracledb.getConnection(
  {   
      user:"user",
      password:"password",
      ConnectString:"IP:PORT/instance_name"
  },

  function(err, connection) {
    if (err) {
      console.error(err.message);
      return;
    }
    console.log('Connection was successful!');
    connection.close(
      function(err) {
        if (err) {
          console.error(err.message);         
          return;
        }
      });
  });
1

There are 1 answers

0
Andrew Rayan On

Please check whether environment for oracle has been set to your local machine and test this code

var oracleConnection = require('knex')({
        client: 'oracledb',
        native: false,
        connection: {
            user: 'username',
            password: 'password',
            connectString: 'connectionstring'
        },
        pool: {
            max: 5,
            min: 1,
            idle: 10000
        }
    });

    oracleConnection.insert({
            ID: '1',
            NAME: 'oracle'
        }).into('TEST_TABLE')
        .then(function() {
            console.log('success')
                //  pg1.commit()
        })
        .catch(function(e) {
            console.log(e.stack)
        });