oracle / node-oracledb

Oracle Database driver for Node.js maintained by Oracle Corp.
http://oracle.github.io/node-oracledb/
Other
2.25k stars 1.07k forks source link

Error: ORA-12170: TNS:Connect timeout occurred #1506

Closed Serban123 closed 2 years ago

Serban123 commented 2 years ago

I want to connect node.js to oracle db and I am getting this error:

Error: ORA-12170: TNS:Connect timeout occurred
    at async run (C:\nodejs\oracle\index.js:21:18) {
  errorNum: 12170,
  offset: 0
}

This is the code that I wrote to make the select

const oracledb = require('oracledb');

oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;

async function run() {

  let connection;

  try {
    oracledb.initOracleClient({libDir: 'C:\\instantclient_21_6'});
  } catch (err) {
    console.error('Whoops!');
    console.error(err);
    process.exit(1);
  }

  try {
    connection = await oracledb.getConnection( {
      user          : "xxx",
      password      : "xxx",
      connectString : "(tnsnames address)))"
 });

    const result = await connection.execute(
      `select * from persons`
    );
    console.log(result.rows);

  } catch (err) {
    console.error(err);
  } finally {
    if (connection) {
      try {
        await connection.close();
      } catch (err) {
        console.error(err);
      }
    }
  }
}

run();

I am a newbie in nodejs and I would like to know what I am doing wrong or be given a working example. I also installed the oracle instant client

cjbj commented 2 years ago

[I edited your question to put triple-backticks around code so it formats nicely]

Your node-oracledb installation appears fine. It is probably the connection string you are using in the application, and/or whether the database is running that is the problem.

Do you know if the database is up? Can you connect with another tool like SQL*Plus?

Is your database on the same machine where Node.js is running?

Serban123 commented 2 years ago

The database is on another machine and I have to connect through a vpn to access it. It works if I access it with toad

Sent from my iPhone

On 21 Jun 2022, at 05:14, Christopher Jones @.***> wrote:

 [I edited your question to put triple-backticks around code so it formats nicely]

Your node-oracledb installation appears fine. It is probably the connection string you are using in the application, and/or whether the database is running that is the problem.

Do you know if the database is up? Can you connect with another tool like SQL*Plus?

Is your database on the same machine where Node.js is running?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

sosoba commented 2 years ago

Use a utility like netstat to check that both connections (from Toad and Node) are to the same IP and with the same source address.

cjbj commented 2 years ago

Can you give a more complete, but still redacted, example of the connect string you are using?

stale[bot] commented 2 years ago

This issue has been automatically marked as inactive because it has not been updated recently. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

This issue has been automatically closed because it has not been updated for a month.