I am writing a Node.js application that pulls data from an Oracle database. The DBA recently migrated the database to another machine, and everything broke.
I've tried re-creating the tnsnames.ora and sqlnet.ora files. I'm fairly sure that they are correct, because sqlplus can connect to the service just fine. But node-oracle keeps reporting the error: "ORA-12154: TNS:could not resolve the connect identifier specified".
This is inexplicable to me. It seems to me that if I have my ORACLE_HOME environment variable set, then both node-oracle and sqlplus should function identically. What am I doing wrong?
I've tried switching to node-db-oracle instead, but it reports the same problem. I'm stumped.
EDIT: This is how I connect:
database = new oracle.Database({
hostname: Preferences["oracle_host"], // FQDN of the database
port: Preferences["oracle_port"],
user: Credentials["oracle_login"],
password: Credentials["oracle_password"],
database: Preferences["oracle_database"]
});
connection = database.connect(function(error) {
if(error) {
Utilities.logger.error(error);
}
else {
Utilities.logger.info("Connected to Oracle database " + Preferences["oracle_host"]);
if(callback) callback.call(this, collection, options);
connection = this;
}
});
Try specifying the TNS_ADMIN
environment variable.
This documentation helped me get connected to an oracle database using node-oracle
. Where I went wrong was I thought the database
property was the name of the database, but in reality it is the service_name
(i.e. the GLOBAL_DBNAME
defined in the listener.ora
file on the Oracle database, not the SID_NAME
).
From what I can tell node-oracle
does not support tnsnames.ora
as it uses the options to build a connection string such as //{hostname}:{port}/{database}
.