Skip to content

Is there any way to verify oracle SQL database connection is still alive or not? #1681

@artbindu

Description

@artbindu

1. Oracle SQL Version: 23.1.1.345

2. Describe the problem:

Recently I'm configuring Oracle SQL Databse with node.js.
I'm trying to verify alive db connection.

This is my db connection sample query:

import * as oracledb from 'oracledb';

export class OracleSQL {
    private static conn;

    static async connect() {
        this.conn = await oracledb.getConnection({
            connectString: "host:port/schema",
            user     :  "username",
            password :  "********"
        });
        // TODO: add some condition to verify database connected successfully
        // if (connection is established) {
            console.log('Database connected successfully');
            return true;
        // }
    }

    static async query(queryStr) {
        // TODO: add some condition to verify connection is still alive or not
        if (!this.conn) {
            let res = await this.connect()
            if (res) {
                return await this.conn.execute(queryStr);
            }
        } else {
            return await this.conn.execute(queryStr);
        }
    }

    static async close() {
        // TODO: add some condition to verify connection already established or not
        // if (connection is established) {
                await this.conn.close()
                .then(() => {
                    console.log('Database disconnected successfully');
                    this.conn = null;
                    return true;
                });
        // }
    }
}

I want to add objective, my connection is already established(alive) or not.

There should be some this.conn object's key or function which should return a Boolean value for connection alive validation


Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions