0
votes
oracledb.getConnection({
      user          : "",
      password      : "",
      connectString : ""
      },
      function(err, connection) {
      if (err) {
          console.log("Error while trying to connect to DB ", err.message);
          callback(err.message);
      } else {
          //My Logic
      }
      });

I am connecting to remote oracledb using the above (pseudo)code. I work in windows environment. Connection string has the URL to connect to the remote DB. Now, if my username/password is incorrect/null, I am able to see that error. But, if the server is switched off, it is not coming into if section handling the error. How to catch the server shutdown error ?

Any leads will be helpful. TIA.

1

1 Answers

0
votes

It is probably waiting for a TCP timeout. You can play with your OS network configuration, and/or configure the Oracle Net layer (which is what handles communication between applications and the database).

Create a file $TNS_ADMIN/sqlnet.ora (don't forget to set TNS_ADMIN so it is read!) Then you can configure SQLNET.OUTBOUND_CONNECT_TIMEOUT.

Depending on your application availability requirements you can also configure various other options like SQLNET.RECV_TIMEOUT and SQLNET.SEND_TIMEOUT. There might be other options that are of interest to you. Finally you may want to create a tnsnames.ora file to configure the DB service setting ('ENABLE=BROKEN').

The 19c Easy Connect Plus syntax is useful for setting some of these options, for example to send keepalive probes every 5 minutes to detect if the connection is still valid you can use a connect string like 'mydbhost.example.com/myservicename?expire_time=5' so you don't need to use tnsnames.ora and sqlnet.ora files for some common settings.