-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there any way to verify oracle SQL database connection is still alive or not? #1681
Comments
@artbindu You can use connection.isHealthy() to check the health status of a connection. |
Meybe |
It does, if you use the |
Thanks @sharadraju import * as oracledb from 'oracledb';
export class OracleSQL {
private static conn;
static async connect() {
try {
this.conn = await oracledb.getConnection({
connectString: "host:port/schema",
user : "username",
password : "********"
});
if (this.conn.isHealthy()) {
console.info("Database connected successfully");
return true;
}
} catch(err) {
console.error('Database connectivity error: ' + err.message);
return false;
}
}
static async query(queryStr) {
console.debug(`Query: ${queryStr}`);
if (!this.conn || (this.conn && !this.conn.isHealthy())) {
let res = await this.connect();
if (res) {
return await this.conn.execute(queryStr);
}
} else {
return await this.conn.execute(queryStr);
}
}
static async close() {
if (this.conn.isHealthy()) {
await this.conn.close().then(() => {
this.conn = null;
console.info("Database disconnected successfully");
});
}
}
} is there any way to handle database error event ?I don't want to use
|
It's nice configuration, both I need to understand to use When I use Mysql server, I used configuration like: import * as sql from 'mssql';
function createConnection(sqlDbConfig) {
const conn = new sql.ConnectionPool(sqlDbConfig);
console.info('DB Connected.');
await conn.connect();
const pool = await this.conn.request();
console.debug('Connection pool initialized.');
// Events to handle Errors
pool.on('error', (err) => {
logger.debug(`Error connecting DB: ${err}`);
conn.close()
});
}
createConnection({
user: 'user',
password: '******',
server: '192.xxx.xxx.xxx',
database: 'dbName',
pool: {
max: 10,
min: 0,
idleTimeoutMillis: 30000,
}
}); Is there any way to configure Actually I want to use this is my oracle sql db connection config: const oracleConfig = {
connectString: "host:port/schema",
user : "username",
password : "********"
poolMax: 10,
poolMin: 0,
poolTimeout: 60
} |
The errors are thrown from the async functions and application needs to catch them. There are no events emitted for error/result. The exceptions are normal in JS else a old callback style might help . These pool examples might help you to get started for your usecase ?: https://github.com/oracle/node-oracledb/blob/main/examples/connectionpool.js https://github.com/oracle/node-oracledb/blob/main/test/pool.js |
@artbindu There are no events emitted for pool or connection objects as pointed out by @sudarshan12s . But we will look into the possibility of adding them for a future release. |
Hi, @sudarshan12s I understand how to use Thank you again |
Hi, @sharadraju I am closing this ticket as I give all valuable information from yours . . . |
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:
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 validationThe text was updated successfully, but these errors were encountered: