Search code examples
node.jsnode-oracledb

Connect to Oracle DB using node.js oracledb


I'm trying to connect to Oracle DB using official node-oracledb driver for Node.js and receive:

ORA-12154: TNS: could not resolve the connect identifier specified. var oracledb = require('oracledb'); oracledb.getConnection({ user: "", password: "", connectString: "DNS=MY;UID=MYNAME;PWD=MYPWD" }, function(err, connection) {...

Same connectString in Excel (connectString="ODBC;DNS=MY;UID=MYNAME;PWD=MYPWD") works fine, as well as tnsping to DB, so it's not about TNS config and enviromental variables.


Solution

  • Please note the documentation on connectString. You can use the Easy Connect Syntax or the Net Service Names syntax. ODBC is not documented as a supported syntax.

    If you look at your ODBC configuration in Windows (Google if needed), you should be able to identify the server and port (default port is 1521) of the database along with the service name you're using. Once you have those values you should be able to create the connectString using easy connect syntax rather easily.

    Also, the user and password values should come through their designated parameters, not through the connectString parameter.