简体   繁体   中英

Node oracledb not detecting if server is shutdown

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM