Index: funcs/func_odbc.c =================================================================== --- funcs/func_odbc.c (revision 310142) +++ funcs/func_odbc.c (working copy) @@ -343,9 +343,26 @@ if (stmt && rows == 0 && ast_str_strlen(insertbuf) != 0) { SQLCloseCursor(stmt); SQLFreeHandle(SQL_HANDLE_STMT, stmt); + if (obj && !transactional) { + ast_odbc_release_obj(obj); + obj = NULL; + } + + /* Reset flag for the next loop */ + transactional = 0; for (dsn = 0; dsn < 5; dsn++) { + if (transactional) { + /* This can only happen second time through or greater. */ + ast_log(LOG_WARNING, "Transactions do not work well with multiple DSNs for 'writehandle'\n"); + } + if (!ast_strlen_zero(query->writehandle[dsn])) { - obj = ast_odbc_request_obj(query->writehandle[dsn], 0); + if ((obj = ast_odbc_retrieve_transaction_obj(chan, query->writehandle[dsn]))) { + transactional = 1; + } else { + obj = ast_odbc_request_obj(query->writehandle[dsn], 0); + transactional = 0; + } if (obj) { stmt = ast_odbc_direct_execute(obj, generic_execute, ast_str_buffer(insertbuf)); } @@ -355,8 +372,10 @@ SQLRowCount(stmt, &rows); break; } - ast_odbc_release_obj(obj); - obj = NULL; + if (obj && !transactional) { + ast_odbc_release_obj(obj); + obj = NULL; + } } } else if (stmt) { status = "SUCCESS";