Closed alevinru closed 8 years ago
There isn't a specific way to do this, though you could execute a simple "select 1" fetch on the connection, checking for error code -308 "Connection was terminated".
I know this is an old question but there does seem to be an undocumented way to check.
var sqlanywhere = require('sqlanywhere');
var conn = sqlanywhere.createConnection();
var conn_params = {
Server: 'demo16',
UserId: 'DBA',
Password: 'sql'
};
conn.connect(conn_params, function (err) {
if (err) throw err;
console.log(conn.connected());
conn.disconnect();
});
That should output "true" in the console.
We have an app with a pool of db connections. Pooling mechanism would like to check if the connection is still alive every time before acquires it. How can we implement this check?