无法将Oracle DB与Node.js连接

时间:2019-03-05 05:44:10

标签: node.js oracledb ora-12560

我尝试将oracle DB与nodejs连接,并且得到如下消息:

ORA-12560:TNS:协议适配器错误

这是我的代码:

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 个答案:

答案 0 :(得分:0)

请检查是否已将oracle环境设置为本地计算机并测试此代码

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