Index: res/res_odbc.c =================================================================== --- res/res_odbc.c (revision 194609) +++ res/res_odbc.c (working copy) @@ -108,20 +108,21 @@ break; } } + } else { + // Error was more severe than a simple SQL Error, connection might be down + ast_log(LOG_WARNING, "SQL Execute error %d! Attempting a reconnect...\n", res); + SQLFreeHandle(SQL_HANDLE_STMT, stmt); + stmt = NULL; + + obj->up = 0; + /* + * While this isn't the best way to try to correct an error, this won't automatically + * fail when the statement handle invalidates. + */ + /* XXX Actually, it might, if we're using a non-pooled connection. Possible race here. XXX */ + odbc_obj_disconnect(obj); + odbc_obj_connect(obj); } - - ast_log(LOG_WARNING, "SQL Execute error %d! Attempting a reconnect...\n", res); - SQLFreeHandle(SQL_HANDLE_STMT, stmt); - stmt = NULL; - - obj->up = 0; - /* - * While this isn't the best way to try to correct an error, this won't automatically - * fail when the statement handle invalidates. - */ - /* XXX Actually, it might, if we're using a non-pooled connection. Possible race here. XXX */ - odbc_obj_disconnect(obj); - odbc_obj_connect(obj); continue; } else obj->last_used = ast_tvnow();