Jonathan Kibet
Jonathan Kibet

Reputation: 701

node-oracledb TNS:listener does not currently know of service requested in connect descriptor

I recently moved from on prem DBs where I used Oracle 11g to Cloud where I needed to connect to Oracle 12c. My nodejs app worked okay on prem but in the cloud, threw the error below

error: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor

Below is the code snippet that my app was using.

oracledb.createPool({
    user: config.DB_USER,
    password: config.DB_PASS,
    connectString: config.DB_HOST + ':' +
    config.DB_PORT + '/' +
    config.DB_NAME,
    poolMin: 20,
    poolIncrement: 0,    
    poolMax: 20
}

After searching around and trying multiple options including swapping : with / nothing seemed to work. I finally managed to get a working solution and I have answered this question below. I hope it helps someone

Upvotes: 0

Views: 2946

Answers (2)

ASammour
ASammour

Reputation: 1009

For whoever is receiving this error while using oracledb package in NodeJS, this is how I fix the issue.

Before, I used this code below, which was producing this error:

ORA-12514: TNS:listener does not currently know of service requested in connect descriptor

 //Old Code Which was producing the error
 connection = await oracledb.getConnection({
        user: "YOUR_USER_NAME_HERE",
        password: "YOUR_PASSWORD_HERE",
        connectString: "YOUR_DB_IP_HERE:YOUR_DB_PORT_HERE/YOUR_SERVICE_NAME_HERE"
 });

Then, after that, I found out that we need to change the value of connectString to give more details. Use the below code:

 //NEW Code After fixing
 connection = await oracledb.getConnection({
        user: "YOUR_USER_NAME_HERE",
        password: "YOUR_PASSWORD_HERE",
        connectString:"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=YOUR_DB_IP_HERE"+")(Port=YOUR_DB_PORT_HERE"+"))(CONNECT_DATA=(SID=YOUR_SERVICE_NAME_HERE"+")))",
 });

And then the issue got fixed!.

Upvotes: 4

Jonathan Kibet
Jonathan Kibet

Reputation: 701

The solution to this problem was changing the connection string as shown in the code snippet below

oracledb.createPool({
    user: config.DB_USER,
    password: config.DB_PASS,
    connectString:"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host="+config.DB_HOST+")(Port="+config.DB_PORT+"))(CONNECT_DATA=(SID="+config.DB_NAME+")))",
    poolMin: 20,
    poolIncrement: 0,    
    poolMax: 20
},

Upvotes: 0

Related Questions