diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/SqlConnectionInternal.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/SqlConnectionInternal.cs index cf0a296b30..ef563fcccd 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/SqlConnectionInternal.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/SqlConnectionInternal.cs @@ -3662,7 +3662,15 @@ private void LoginWithFailover( continue; } - if (IsDoNotRetryConnectError(sqlex) || timeout.IsExpired) + // If state != closed, indicates that the parser encountered an error while + // processing the login response (e.g. an explicit error token). Transient + // network errors that impact connectivity will result in parser state being + // closed. Only network-level errors should trigger failover alternation; + // login-phase errors (like transient errors) should be thrown so they can + // be handled by the outer ConnectRetryCount loop. + if (_parser?.State is not TdsParserState.Closed || + IsDoNotRetryConnectError(sqlex) || + timeout.IsExpired) { // No more time to try again. // Caller will call LoginFailure()