c++ - QODBC SQL timeout -
i have c++ qt application running on many devices, needs communicate ms sql server. i'm using qodbc3 (unixodbc) driver.
the sql connection once initialized , connected , used repeatedly. this, query runs fast (max 20ms).
everythink works fine when there no connection issue. when network connection lost short time, sql connection can not "reconnect".
i tried check if connection on before each query attempt, qsqldatabase::isopen()
returns true unless close()
called. not change after network issue. in oppinion, best way setting timer in odbc driver short time , try reconnect when timeout goes off. timeout in odbc set cca 15 minutes , not able set different value.
sqlconnection.setconnectoptions("sql_attr_connection_timeout=5");
this command seems change nothing, tried complete nonsense in string, no error or something.
my next try ping server every time before running query, if network connection on again, ping goes true , sql connection still broken.
my "temporary" solution open sql connection before each query , close afterwards (with ping preceding opening). solution prolongs each query cca 500ms , not realy happy it.
four possible solutions side:
- succesfully set timeout in odbc driver
- implement own timeout in higher level above qsqldatabase
- detect network issues before trying run sql query
- keep temporary solution , pretend can not changed :-(
Comments
Post a Comment