mariano / node-db-oracle

Oracle database bindings for Node.js
http://nodejsdb.org
141 stars 34 forks source link

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

Open orencio opened 12 years ago

orencio commented 12 years ago

Hello. I'm trying to connect to my database, but I always get same response:

$ node ora.js
WARNING: ev_ref is deprecated, use uv_ref
WARNING: ev_unref is deprecated, use uv_unref
Connection error: ORA-12154: TNS:could not resolve the connect identifier specified

The code is based on the example:

var or = require('db-oracle');
var connection_datas = {
    hostname: 'example-serv.org',
//    port: '1521',
    user: 'us',
    password: 'pw',
    database: 'des'
};
var o = new or.Database(connection_datas);

o.connect(function(error) {
    if (error) {
    return console.log('Connection error: ' + error);
    }

    this.query().select('*').from('dual').execute(function(error, rows) {
    if (error) return console.log('Error' + error);
    console.log(rows.length + ' rows.');
    console.log(rows);
    });
});

I don't know if des is database service name or is listener database name, so I've tried with service name too (databse: 'des.example-serv.org') but I've had same result.

I can't specify port because I get this error (uncommenting port line):

$ node ora.js

/home/aoramire/Desarrollo/tmp/ora.js:9
var o = new or.Database(connection_datas);
        ^
Error: Option "port" must be a valid UINT32
    at Object.<anonymous> (/home/aoramire/Desarrollo/tmp/ora.js:9:9)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

Here is my env. vars.:


$ set | grep -E "ORA|OCI|TNS|LD_LIB"
LD_LIBRARY_PATH=:/var/lib/oracle/app/oracle/product/11.2.0/client_1/lib
OCI_INCLUDE_DIR=/var/lib/oracle/app/oracle/product/11.2.0/client_1/rdbms/public
OCI_LIB_DIR=/var/lib/oracle/app/oracle/product/11.2.0/client_1/lib
ORACLE_BASE=/var/lib/oracle
ORACLE_HOME=/var/lib/oracle/app/oracle/product/11.2.0/client_1
TNS_ADMIN=/var/lib/oracle/app/oracle/product/11.2.0/client_1/network/admin

My tnsnames.ora:


$ cat $TNS_ADMIN/tnsnames.ora
# tnsnames.ora Network Configuration File: /var/lib/oracle/app/oracle/product/11.2.0/client_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

DES =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = example-serv.org)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = SHARED)
      (SERVICE_NAME = des.example-serv.org)
    )
  )

And, ping to database:

$ tnsping des

TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 16-SEP-2012 08:51:37

Copyright (c) 1997, 2009, Oracle.  All rights reserved.

Used parameter files:
/var/lib/oracle/app/oracle/product/11.2.0/client_1/network/admin/sqlnet.ora

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = example-serv.org)(PORT = 1521))) (CONNECT_DATA = (SERVER = SHARED) (SERVICE_NAME = des.example-serv.org)))
OK (360 msec)

What is the problem? Thanks.

orencio commented 12 years ago

Any suggestions?

shuracwf commented 12 years ago

about "WARNING: ev_ref is deprecated, use uv_ref" --this is Node's warning when you use Node.js verson above 0.8.X

You do not need config the tnsnames.ora,you can do it directory like this:

var or = require('db-oracle'); var connection_datas = { hostname: 'example-serv.org',//host name or ip address port: '1521',//oracle listener port user: 'us', password: 'pw', database: 'des' }; var o = new or.Database(connection_datas);

cawkLUVA commented 11 years ago

Were you ever able to resolve this using TNS names? I'm having a similar issue.