最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ORA-12514 error while using node oracle-db npm packagae - Stack Overflow

programmeradmin0浏览0评论

Currently, I am working on a project which requires the backend to be done in oracle. I used the given link and installed the node-oracledb using npm on my mac. My file contents are as follows

var oracledb = require('oracledb');

oracledb.getConnection(
{
user          : 'username',
password      : 'password',
connectString : 'username/password//hostname:port/sid'
function(err, connection)
{
if (err) {
  console.error(err.message);
  return;
}else{
    connection.execute(
  "SELECT * from TableName",
  function(err, result)
  {
    if (err) { console.error(err); return; }
    console.log(result.rows);
  });
 }
});

When I run node filename.js I get the following error

ORA-12154: TNS:could not resolve the connect identifier specified

I am using node version is v7.0.0 and npm version is v3.10.8. Also my oracle database is a 11g instance on the cloud. Can somebody let me know as to what am I doing wrong?

Currently, I am working on a project which requires the backend to be done in oracle. I used the given link and installed the node-oracledb using npm on my mac. My file contents are as follows

var oracledb = require('oracledb');

oracledb.getConnection(
{
user          : 'username',
password      : 'password',
connectString : 'username/password//hostname:port/sid'
function(err, connection)
{
if (err) {
  console.error(err.message);
  return;
}else{
    connection.execute(
  "SELECT * from TableName",
  function(err, result)
  {
    if (err) { console.error(err); return; }
    console.log(result.rows);
  });
 }
});

When I run node filename.js I get the following error

ORA-12154: TNS:could not resolve the connect identifier specified

I am using node version is v7.0.0 and npm version is v3.10.8. Also my oracle database is a 11g instance on the cloud. Can somebody let me know as to what am I doing wrong?

Share Improve this question asked Jan 16, 2017 at 17:18 shubhamagiwal92shubhamagiwal92 1,4324 gold badges25 silver badges50 bronze badges 1
  • I know this issue has been resolved but I am facing similar problem. I have follwed the direction mention in node-oracledb. I have installed instantclient basic and sdk and set their path. As soon as I install oracle 11g express I get error oracledb module cannot be found. When I uninstall 11g express then I get error ORA-12541: TNS:no listener. Can you please guide how I can install 11g and what would be my connection string? – user557657 Commented Apr 7, 2017 at 12:40
Add a ment  | 

1 Answer 1

Reset to default 10

It looks like your connectString is wrong, according to the Docs it's just hostname:port/sid

var oracledb = require('oracledb');

oracledb.getConnection(
  {
    user          : "hr",
    password      : "wele",
    connectString : "hostname:port/sid"
  })
  .then(function(conn) {
    return conn.execute(
      "SELECT department_id, department_name " +
        "FROM departments " +
        "WHERE manager_id < :id",
      [110]  // bind value for :id
    )
      .then(function(result) {
        console.log(result.rows);
        return conn.close();
      })
      .catch(function(err) {
        console.error(err);
        return conn.close();
      });
  })
  .catch(function(err) {
    console.error(err);
  });

Edit:

As of atleast July 2019 (probably sometime before July) connectString : "hostname:port/sid" no longer works with oracledb printing the error: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor Instead, as found here you can to set connectString to (DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = YOUR_HOST)(PORT = YOUR_PORT))(CONNECT_DATA =(SID= YOUR_SID))) to connect to a database using SID.

So, the updated getConnection (in regards to the question) would be:

oracledb.getConnection(
 {
   user          : "hr",
   password      : "wele",
   connectString : "(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = port))(CONNECT_DATA =(SID= sid)))"
 })
发布评论

评论列表(0)

  1. 暂无评论