Skip to content

Commit e6a7c54

Browse files
subrata-msCopilot
andauthored
Update mssql_python/pybind/connection/connection.cpp
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent f912215 commit e6a7c54

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

mssql_python/pybind/connection/connection.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)