File tree Expand file tree Collapse file tree
mssql_python/pybind/connection Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -148,6 +148,17 @@ void Connection::disconnect() {
148148 // from destructors, reset() failure paths, and pool cleanup.
149149 // Throwing here during stack unwinding causes std::terminate().
150150 LOG_ERROR (" SQLDisconnect failed (ret=%d), forcing handle cleanup" , ret);
151+
152+ // Best-effort: retrieve and log ODBC diagnostics for debuggability.
153+ // This must not throw, to keep disconnect noexcept-safe.
154+ try {
155+ ErrorInfo err = SQLCheckError_Wrap (SQL_HANDLE_DBC, _dbcHandle, ret);
156+ std::string diagMsg = WideToUTF8 (err.ddbcErrorMsg );
157+ LOG_ERROR (" SQLDisconnect diagnostics: %s" , diagMsg.c_str ());
158+ } catch (...) {
159+ // Swallow all exceptions: cleanup paths must not throw.
160+ LOG_ERROR (" SQLDisconnect: failed to retrieve ODBC diagnostics" );
161+ }
151162 }
152163 // Always free the handle regardless of SQLDisconnect result
153164 _dbcHandle.reset ();
You can’t perform that action at this time.
0 commit comments