【问题标题】:Unable to connect oracle db with nodejs无法将 oracle db 与 nodejs 连接
【发布时间】:2019-11-11 17:57:51
【问题描述】:

我尝试用nodejs连接oracle DB,得到如下信息:

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

【问题讨论】:

  • 详细一点,我试过用SQL developer连接DB,好像成功了,而且DB是远程DB,不在同一个服务器上。
  • 将“ConnectString”更改为“connectString”或“connectionString”(我们都检查)。
  • 非常感谢。很奇怪,我把这段代码放到另一个文件中,它就可以工作了。我无法区分这些。

标签: node.js node-oracledb ora-12560


【解决方案1】:

请检查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)
        });

【讨论】:

    猜你喜欢
    • 2018-09-22
    • 1970-01-01
    • 2016-01-12
    • 2011-12-11
    • 2016-03-04
    • 1970-01-01
    • 2016-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多