0

I am using oracledb in my Node server for connecting to a TNS Connection Alias. This is my code:

const oracledb = require('oracledb');

    oracledb.getConnection(
        {
            user: "test",
            password: "test",
            connectString: "ADMISSIONS"
        },
        function (err, connection) {
            if (err) {
                logger.error("Error is: " + err.message);
                callback(null, err);
                return;
            } else {
                logger.loud("Connection successful!");
            }
});
}

However, I am getting this error:

TNS:could not resolve the connect identifier specified

I am sure my connectString is wrong. Can anyone please help with what should be the value of connectString if I want to connect to a TNS Connection Alias called Admissions ? Please note this is NOT a localhost/XE connection.

MT0
  • 143,790
  • 11
  • 59
  • 117
HelmBurger
  • 1,168
  • 5
  • 15
  • 35
  • Are you able to connect using this TNS connection alias using other applications, say `sqlplus` ? This error usually occurs when your entry in TNS entry is wrong/ not consistent with your network. – Malice Aug 15 '17 at 05:04
  • This is a TNS related error rather than a `'oracledb'` error – Malice Aug 15 '17 at 05:05
  • I am able to connect to "Admissions" alias successfully through SQL Developer upon defining "Connecting type" as TNS – HelmBurger Aug 15 '17 at 05:06
  • `ADMISSIONS` or `Admissions` ? And in which file have you defined the alias. – Malice Aug 15 '17 at 05:09
  • "ADMISSIONS". The alias is defined by our organisation and I dont have access to the file (or system) where it is defined. It just appears in the drop down menu of TNS Connection type in SQL Developer – HelmBurger Aug 15 '17 at 05:13
  • I'm pretty sure that the SQL developer picks it up from some place, where `'oracledb'` is not looking for... – Malice Aug 15 '17 at 05:17
  • https://stackoverflow.com/questions/425029/oracle-tns-names-not-showing-when-adding-new-connection-to-sql-developer – Malice Aug 15 '17 at 05:17
  • So all I need to do is to point oracledb connectString to the file called **tnsnames.ora** ? – HelmBurger Aug 15 '17 at 05:19
  • Your connection string should be in `tnsnames.ora` – Malice Aug 15 '17 at 05:24
  • do a `find` for `tnsname.ora` on your file system. You might be able to spot it – Malice Aug 15 '17 at 05:25
  • I did a find for tnsname.ora, but couldn't find it anywhere in my system. Is it possible that SQL developer is picking it up from some network location? I assume that's what's happening that's why I can't see it in my local FS – HelmBurger Aug 15 '17 at 05:29
  • https://stackoverflow.com/questions/2019230/use-tnsnames-ora-in-oracle-sql-developer – Malice Aug 15 '17 at 05:30
  • You are a legend! I copied the latest tnsnames.ora file form another machine into my DEV machine and it works. Thanks so much. – HelmBurger Aug 15 '17 at 05:37

1 Answers1

0

The issue was outdated tnsnames.ora file. I copied the latest version of tnsnames.ora file into my /etc directory and the connection is successful. Thanks to @Malice

HelmBurger
  • 1,168
  • 5
  • 15
  • 35