Hi dear dev team,

Is there a way to check if ODBC connection is alive and database is accessible from my module?

For example when I am executing the following in my code and database is down:
switch_odbc_handle_callback_exec(globals.backup_odbc, sql, my_func_callback, &pdata, NULL) != SWITCH_ODBC_SUCCESS

it tries to reconnect 120 times to the database, before it gives up.

I have 2 options: 
1. Check if the database is alive before executing this code (preferred)
2. Reduce max_tries to , say 3 from 120 (not preferred as it requires change in switch_odbc.c).


Could you please hint?

Thank you,
Vitalie


2010/4/25 Vitalii Colosov <vetali100@gmail.com>
Hi,

I am using core ODBC for MySQL connect.

Trying to implement failover using 2 servers - main and backup.
If main server is not responding, it should try to query backup server.

The following is used in my module:

if (switch_odbc_handle_callback_exec(globals.master_odbc, sql, my_func_callback, &pdata, NULL) != SWITCH_ODBC_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(***)Error running query on master database: [%s]\n", sql);

switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "(***)Trying backup database: [%s]\n", globals.backup_odbc);


if (switch_odbc_handle_callback_exec(globals.backup_odbc, sql, my_func_callback, &pdata, NULL) != SWITCH_ODBC_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "(***)Error running query on master and backup database: [%s]\n", sql);
} 
}
...



Right now it tries to reconnect to main server 120 times before it gives up and goes to backup server.

I found the following in the switch_odbc.c:
int max_tries = 120;


Is there is a way to disable this check, so if it will not be able to connect to master, it will immediate go to backup server?
I know I can change the source, but this will be already "customized core" - don't want to go in this direction.


Or maybe there is a better way to handle database fail over in my module?


Thank you,
Vitalie