Skip to content
Prev Previous commit
Next Next commit
Update mssql_python/pybind/connection/connection.cpp
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
  • Loading branch information
subrata-ms and Copilot authored Apr 1, 2026
commit e6a7c54b3414d0ac01e22de84e86120c7d02fe26
11 changes: 11 additions & 0 deletions mssql_python/pybind/connection/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ void Connection::disconnect() {
// from destructors, reset() failure paths, and pool cleanup.
// Throwing here during stack unwinding causes std::terminate().
LOG_ERROR("SQLDisconnect failed (ret=%d), forcing handle cleanup", ret);
Comment thread
subrata-ms marked this conversation as resolved.
Outdated

// Best-effort: retrieve and log ODBC diagnostics for debuggability.
// This must not throw, to keep disconnect noexcept-safe.
try {
ErrorInfo err = SQLCheckError_Wrap(SQL_HANDLE_DBC, _dbcHandle, ret);
std::string diagMsg = WideToUTF8(err.ddbcErrorMsg);
LOG_ERROR("SQLDisconnect diagnostics: %s", diagMsg.c_str());
} catch (...) {
// Swallow all exceptions: cleanup paths must not throw.
LOG_ERROR("SQLDisconnect: failed to retrieve ODBC diagnostics");
}
}
// Always free the handle regardless of SQLDisconnect result
_dbcHandle.reset();
Expand Down
Loading