From 110222c13fc04330ece9a62e54797911f526bc4d Mon Sep 17 00:00:00 2001 From: Matthias_Huygelen Date: Tue, 20 Jan 2026 10:55:15 +0100 Subject: [PATCH 1/6] expose-default-transient-error-codes --- .../SqlConfigurableRetryFactory.xml | 43 ++++++++++++++++++- .../SqlConfigurableRetryFactory.cs | 14 +++++- .../SQL/RetryLogic/RetryLogicTestHelper.cs | 36 ++-------------- 3 files changed, 57 insertions(+), 36 deletions(-) diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml index 730a592b6f..86264779e7 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml @@ -1,4 +1,4 @@ - + @@ -113,6 +113,42 @@ A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) (Microsoft SQL Server, Error: 233) + + 64 + + A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 - The specified network name is no longer available.) (Microsoft SQL Server, Error: 64) + + + + 20 + The instance of SQL Server you attempted to connect to does not support encryption. + + + 0 + A connection was successfully established with the server, but then an error occurred during the pre-login handshake. + + + -2 + Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. + + + 207 + Invalid column name. + + + 18456 + + Login failed for user. (Using managed identity in Azure Sql Server throws 18456 for non-existent database instead of 4060.) + + + + 42108 + Can not connect to the SQL pool since it is paused. Please resume the SQL pool and try again. + + + 42109 + The SQL pool is warming up. Please try again. + @@ -250,5 +286,10 @@ + + + Gets a readonly replica of the inner transient error list. + + diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs index 859c3ef510..5410fd38c5 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Diagnostics; namespace Microsoft.Data.SqlClient @@ -59,8 +60,17 @@ private static readonly HashSet s_defaultTransientErrors 10928, // Resource ID: %d. The %s limit for the database is %d and has been reached. For more information, see http://go.microsoft.com/fwlink/?LinkId=267637. 10060, // An error has occurred while establishing a connection to the server. When connecting to SQL Server, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) (Microsoft SQL Server, Error: 10060) 997, // A connection was successfully established with the server, but then an error occurred during the login process. (provider: Named Pipes Provider, error: 0 - Overlapped I/O operation is in progress) - 233 // A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) (Microsoft SQL Server, Error: 233) - }; + 233, // A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) (Microsoft SQL Server, Error: 233) + 64, + 20, + 0, + -2, // Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. + 207, // invalid column name + 18456 // Using managed identity in Azure Sql Server throws 18456 for non-existent database instead of 4060. + }; + + /// + public static ReadOnlyCollection DefaultTransientErrors => new([.. s_defaultTransientErrors]); /// public static SqlRetryLogicBaseProvider CreateExponentialRetryProvider(SqlRetryLogicOption retryLogicOption) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/RetryLogic/RetryLogicTestHelper.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/RetryLogic/RetryLogicTestHelper.cs index c9a64e5ef1..3bbd3c3512 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/RetryLogic/RetryLogicTestHelper.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/RetryLogic/RetryLogicTestHelper.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Text.RegularExpressions; @@ -13,37 +14,6 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests { public class RetryLogicTestHelper { - private static readonly HashSet s_defaultTransientErrors - = new HashSet - { - 1204, // The instance of the SQL Server Database Engine cannot obtain a LOCK resource at this time. Rerun your statement when there are fewer active users. Ask the database administrator to check the lock and memory configuration for this instance, or to check for long-running transactions. - 1205, // Transaction (Process ID) was deadlocked on resources with another process and has been chosen as the deadlock victim. Rerun the transaction - 1222, // Lock request time out period exceeded. - 49918, // Cannot process request. Not enough resources to process request. - 49919, // Cannot process create or update request. Too many create or update operations in progress for subscription "%ld". - 49920, // Cannot process request. Too many operations in progress for subscription "%ld". - 4060, // Cannot open database "%.*ls" requested by the login. The login failed. - 4221, // Login to read-secondary failed due to long wait on 'HADR_DATABASE_WAIT_FOR_TRANSITION_TO_VERSIONING'. The replica is not available for login because row versions are missing for transactions that were in-flight when the replica was recycled. The issue can be resolved by rolling back or committing the active transactions on the primary replica. Occurrences of this condition can be minimized by avoiding long write transactions on the primary. - 42108, // Can not connect to the SQL pool since it is paused. Please resume the SQL pool and try again. - 42109, // The SQL pool is warming up. Please try again. - 40143, // The service has encountered an error processing your request. Please try again. - 40613, // Database '%.*ls' on server '%.*ls' is not currently available. Please retry the connection later. If the problem persists, contact customer support, and provide them the session tracing ID of '%.*ls'. - 40501, // The service is currently busy. Retry the request after 10 seconds. Incident ID: %ls. Code: %d. - 40540, // The service has encountered an error processing your request. Please try again. - 40197, // The service has encountered an error processing your request. Please try again. Error code %d. - 10929, // Resource ID: %d. The %s minimum guarantee is %d, maximum limit is %d and the current usage for the database is %d. However, the server is currently too busy to support requests greater than %d for this database. For more information, see http://go.microsoft.com/fwlink/?LinkId=267637. Otherwise, please try again later. - 10928, // Resource ID: %d. The %s limit for the database is %d and has been reached. For more information, see http://go.microsoft.com/fwlink/?LinkId=267637. - 10060, // An error has occurred while establishing a connection to the server. When connecting to SQL Server, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) (Microsoft SQL Server, Error: 10060) - 997, // A connection was successfully established with the server, but then an error occurred during the login process. (provider: Named Pipes Provider, error: 0 - Overlapped I/O operation is in progress) - 233, // A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) (Microsoft SQL Server, Error: 233) - 64, - 20, - 0, - -2, // Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. - 207, // invalid column name - 18456 // Using managed identity in Azure Sql Server throws 18456 for non-existent database instead of 4060. - }; - public static readonly Regex FilterDmlStatements = new Regex( @"\b(INSERT( +INTO)|UPDATE|DELETE|TRUNCATE)\b", RegexOptions.Compiled | RegexOptions.IgnoreCase); @@ -63,7 +33,7 @@ public static TheoryData GetConnectionStringA NumberOfTries = numberOfRetries, DeltaTime = deltaTime ?? TimeSpan.FromMilliseconds(10), MaxTimeInterval = maxInterval, - TransientErrors = transientErrorCodes ?? s_defaultTransientErrors, + TransientErrors = transientErrorCodes ?? SqlConfigurableRetryFactory.DefaultTransientErrors, AuthorizedSqlCondition = RetryPreCondition(unauthorizedStatementRegex) }; @@ -111,7 +81,7 @@ private static IEnumerable GetRetryStrategiesTyped(Sq public static IEnumerable GetDefaultTransientErrorCodes(params int[] additionalCodes) { - var transientErrorCodes = new HashSet(s_defaultTransientErrors); + var transientErrorCodes = new HashSet(SqlConfigurableRetryFactory.DefaultTransientErrors); foreach (int additionalCode in additionalCodes) { transientErrorCodes.Add(additionalCode); From cdbfe53e6a56a16d1d32e60a5a7d9ca89301fb55 Mon Sep 17 00:00:00 2001 From: Matthias_Huygelen Date: Tue, 20 Jan 2026 11:26:32 +0100 Subject: [PATCH 2/6] fixed comments --- .../netcore/ref/Microsoft.Data.SqlClient.cs | 2 ++ .../netfx/ref/Microsoft.Data.SqlClient.cs | 2 ++ .../Reliability/SqlConfigurableRetryFactory.cs | 12 +++++++----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs index 0a04d047f8..d4b1da2907 100644 --- a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs @@ -1971,6 +1971,8 @@ public sealed class SqlRetryLogicOption /// public sealed class SqlConfigurableRetryFactory { + /// + public static System.Collections.ObjectModel.ReadOnlyCollection DefaultTransientErrors { get { throw null; } } /// public static SqlRetryLogicBaseProvider CreateExponentialRetryProvider(SqlRetryLogicOption retryLogicOption) { throw null; } /// diff --git a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs index e662fc0560..29e6d868fc 100644 --- a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs @@ -1954,6 +1954,8 @@ public sealed class SqlRetryLogicOption /// public sealed class SqlConfigurableRetryFactory { + /// + public static System.Collections.ObjectModel.ReadOnlyCollection DefaultTransientErrors { get { throw null; } } /// public static SqlRetryLogicBaseProvider CreateExponentialRetryProvider(SqlRetryLogicOption retryLogicOption) { throw null; } /// diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs index 5410fd38c5..b5e76350fe 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs @@ -60,17 +60,19 @@ private static readonly HashSet s_defaultTransientErrors 10928, // Resource ID: %d. The %s limit for the database is %d and has been reached. For more information, see http://go.microsoft.com/fwlink/?LinkId=267637. 10060, // An error has occurred while establishing a connection to the server. When connecting to SQL Server, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) (Microsoft SQL Server, Error: 10060) 997, // A connection was successfully established with the server, but then an error occurred during the login process. (provider: Named Pipes Provider, error: 0 - Overlapped I/O operation is in progress) - 233, // A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) (Microsoft SQL Server, Error: 233) - 64, - 20, - 0, + 233, // A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) (Microsoft SQL Server, Error: 233) + 64, // A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 - The specified network name is no longer available.) + 20, // The instance of SQL Server you attempted to connect to does not support encryption. + 0, // A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) -2, // Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. 207, // invalid column name 18456 // Using managed identity in Azure Sql Server throws 18456 for non-existent database instead of 4060. }; + private static readonly ReadOnlyCollection s_defaultTransientErrorsReadOnly = new([.. s_defaultTransientErrors]); + /// - public static ReadOnlyCollection DefaultTransientErrors => new([.. s_defaultTransientErrors]); + public static ReadOnlyCollection DefaultTransientErrors => s_defaultTransientErrorsReadOnly; /// public static SqlRetryLogicBaseProvider CreateExponentialRetryProvider(SqlRetryLogicOption retryLogicOption) From 1c96948dcc4ef65eb998929b649ceb4d38389946 Mon Sep 17 00:00:00 2001 From: Matthias_Huygelen Date: Tue, 20 Jan 2026 13:04:07 +0100 Subject: [PATCH 3/6] Fix comments --- .../SqlConfigurableRetryFactory.xml | 6 +++--- .../netcore/ref/Microsoft.Data.SqlClient.cs | 5 +++-- .../netfx/ref/Microsoft.Data.SqlClient.cs | 4 ++-- .../Reliability/SqlConfigurableRetryFactory.cs | 15 ++++++--------- .../SQL/RetryLogic/RetryLogicTestHelper.cs | 4 ++-- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml index 86264779e7..037f5553e3 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml @@ -286,10 +286,10 @@ - + - Gets a readonly replica of the inner transient error list. + Gets a readonly replica of the transient error list. - + diff --git a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs index d4b1da2907..3dacfa4ceb 100644 --- a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs @@ -1971,8 +1971,9 @@ public sealed class SqlRetryLogicOption /// public sealed class SqlConfigurableRetryFactory { - /// - public static System.Collections.ObjectModel.ReadOnlyCollection DefaultTransientErrors { get { throw null; } } + /// + public static System.Collections.ObjectModel.ReadOnlyCollection s_defaultTransientErrors { get { throw null; } } + /// public static SqlRetryLogicBaseProvider CreateExponentialRetryProvider(SqlRetryLogicOption retryLogicOption) { throw null; } /// diff --git a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs index 29e6d868fc..1d480ad94d 100644 --- a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs @@ -1954,8 +1954,8 @@ public sealed class SqlRetryLogicOption /// public sealed class SqlConfigurableRetryFactory { - /// - public static System.Collections.ObjectModel.ReadOnlyCollection DefaultTransientErrors { get { throw null; } } + /// + public static System.Collections.ObjectModel.ReadOnlyCollection s_defaultTransientErrors { get { throw null; } } /// public static SqlRetryLogicBaseProvider CreateExponentialRetryProvider(SqlRetryLogicOption retryLogicOption) { throw null; } /// diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs index b5e76350fe..32455c06df 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs @@ -37,10 +37,12 @@ public sealed class SqlRetryLogicOption public sealed class SqlConfigurableRetryFactory { private readonly static object s_syncObject = new(); + /// Default known transient error numbers. - private static readonly HashSet s_defaultTransientErrors - = new HashSet - { + /// + public static readonly ReadOnlyCollection s_defaultTransientErrors + = new( + [ 1204, // The instance of the SQL Server Database Engine cannot obtain a LOCK resource at this time. Rerun your statement when there are fewer active users. Ask the database administrator to check the lock and memory configuration for this instance, or to check for long-running transactions. 1205, // Transaction (Process ID) was deadlocked on resources with another process and has been chosen as the deadlock victim. Rerun the transaction 1222, // Lock request time out period exceeded. @@ -67,12 +69,7 @@ private static readonly HashSet s_defaultTransientErrors -2, // Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. 207, // invalid column name 18456 // Using managed identity in Azure Sql Server throws 18456 for non-existent database instead of 4060. - }; - - private static readonly ReadOnlyCollection s_defaultTransientErrorsReadOnly = new([.. s_defaultTransientErrors]); - - /// - public static ReadOnlyCollection DefaultTransientErrors => s_defaultTransientErrorsReadOnly; + ]); /// public static SqlRetryLogicBaseProvider CreateExponentialRetryProvider(SqlRetryLogicOption retryLogicOption) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/RetryLogic/RetryLogicTestHelper.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/RetryLogic/RetryLogicTestHelper.cs index 3bbd3c3512..f6d7d563b7 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/RetryLogic/RetryLogicTestHelper.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/RetryLogic/RetryLogicTestHelper.cs @@ -33,7 +33,7 @@ public static TheoryData GetConnectionStringA NumberOfTries = numberOfRetries, DeltaTime = deltaTime ?? TimeSpan.FromMilliseconds(10), MaxTimeInterval = maxInterval, - TransientErrors = transientErrorCodes ?? SqlConfigurableRetryFactory.DefaultTransientErrors, + TransientErrors = transientErrorCodes ?? SqlConfigurableRetryFactory.s_defaultTransientErrors, AuthorizedSqlCondition = RetryPreCondition(unauthorizedStatementRegex) }; @@ -81,7 +81,7 @@ private static IEnumerable GetRetryStrategiesTyped(Sq public static IEnumerable GetDefaultTransientErrorCodes(params int[] additionalCodes) { - var transientErrorCodes = new HashSet(SqlConfigurableRetryFactory.DefaultTransientErrors); + var transientErrorCodes = new HashSet(SqlConfigurableRetryFactory.s_defaultTransientErrors); foreach (int additionalCode in additionalCodes) { transientErrorCodes.Add(additionalCode); From f4358f4c92dc0f5b1cff90ff83bdbff65f061b1e Mon Sep 17 00:00:00 2001 From: Matthias_Huygelen Date: Tue, 20 Jan 2026 15:47:09 +0100 Subject: [PATCH 4/6] comments --- .../SqlConfigurableRetryFactory.xml | 134 +++++++++--------- .../netcore/ref/Microsoft.Data.SqlClient.cs | 5 +- .../netfx/ref/Microsoft.Data.SqlClient.cs | 4 +- .../SqlConfigurableRetryFactory.cs | 38 ++--- .../SQL/RetryLogic/RetryLogicTestHelper.cs | 4 +- 5 files changed, 92 insertions(+), 93 deletions(-) diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml index 037f5553e3..f3c277e4e1 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml @@ -14,131 +14,117 @@ Description - 1204 - - The instance of the SQL Server Database Engine cannot obtain a LOCK resource at this time. Rerun your statement when there are fewer active users. Ask the database administrator to check the lock and memory configuration for this instance, or to check for long-running transactions. - - - - 1205 - - Transaction (Process ID) was deadlocked on resources with another process and has been chosen as the deadlock victim. Rerun the transaction. - + -2 + Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. - 1222 - Lock request time out period exceeded. + 0 + A connection was successfully established with the server, but then an error occurred during the pre-login handshake. - 49918 - Cannot process request. Not enough resources to process request. + 20 + The instance of SQL Server you attempted to connect to does not support encryption. - 49919 + 64 - Cannot process create or update request. Too many create or update operations in progress for subscription "%ld". + A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 - The specified network name is no longer available.) (Microsoft SQL Server, Error: 64) - 49920 - Cannot process request. Too many operations in progress for subscription "%ld". - - - 4060 - Cannot open database "%.*ls" requested by the login. The login failed. + 207 + Invalid column name. - 4221 + 233 - Login to read-secondary failed due to long wait on 'HADR_DATABASE_WAIT_FOR_TRANSITION_TO_VERSIONING'. The replica is not available for login because row versions are missing for transactions that were in-flight when the replica was recycled. The issue can be resolved by rolling back or committing the active transactions on the primary replica. Occurrences of this condition can be minimized by avoiding long write transactions on the primary. + A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) (Microsoft SQL Server, Error: 233) - 40143 - The service has encountered an error processing your request. Please try again. - - - 40613 + 997 - Database '%.*ls' on server '%.*ls' is not currently available. Please retry the connection later. If the problem persists, contact customer support, and provide them the session tracing ID of '%.*ls'. + A connection was successfully established with the server, but then an error occurred during the login process. (provider: Named Pipes Provider, error: 0 - Overlapped I/O operation is in progress) - 40501 - The service is currently busy. Retry the request after 10 seconds. Incident ID: %ls. Code: %d. + 1204 + + The instance of the SQL Server Database Engine cannot obtain a LOCK resource at this time. Rerun your statement when there are fewer active users. Ask the database administrator to check the lock and memory configuration for this instance, or to check for long-running transactions. + - 40540 - The service has encountered an error processing your request. Please try again. + 1205 + + Transaction (Process ID) was deadlocked on resources with another process and has been chosen as the deadlock victim. Rerun the transaction. + - 40197 - The service has encountered an error processing your request. Please try again. Error code %d. + 1222 + Lock request time out period exceeded. - 10929 - - Resource ID: %d. The %s minimum guarantee is %d, maximum limit is %d and the current usage for the database is %d. However, the server is currently too busy to support requests greater than %d for this database. For more information, see https://learn.microsoft.com/azure/azure-sql/database/resource-limits-logical-server. Otherwise, please try again later. - + 4060 + Cannot open database "%.*ls" requested by the login. The login failed. - 10928 + 4221 - Resource ID: %d. The %s limit for the database is %d and has been reached. For more information, see https://learn.microsoft.com/azure/azure-sql/database/resource-limits-logical-server. + Login to read-secondary failed due to long wait on 'HADR_DATABASE_WAIT_FOR_TRANSITION_TO_VERSIONING'. The replica is not available for login because row versions are missing for transactions that were in-flight when the replica was recycled. The issue can be resolved by rolling back or committing the active transactions on the primary replica. Occurrences of this condition can be minimized by avoiding long write transactions on the primary. - 10060 - - An error has occurred while establishing a connection to the server. When connecting to SQL Server, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) (Microsoft SQL Server, Error: 10060) - + 10053 + Could not convert the data value due to reasons other than sign mismatch or overflow. 10054 The data value for one or more columns overflowed the type used by the provider. - 10053 - Could not convert the data value due to reasons other than sign mismatch or overflow. + 10060 + + An error has occurred while establishing a connection to the server. When connecting to SQL Server, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) (Microsoft SQL Server, Error: 10060) + - 997 + 10928 - A connection was successfully established with the server, but then an error occurred during the login process. (provider: Named Pipes Provider, error: 0 - Overlapped I/O operation is in progress) + Resource ID: %d. The %s limit for the database is %d and has been reached. For more information, see https://learn.microsoft.com/azure/azure-sql/database/resource-limits-logical-server. - 233 + 10929 - A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) (Microsoft SQL Server, Error: 233) + Resource ID: %d. The %s minimum guarantee is %d, maximum limit is %d and the current usage for the database is %d. However, the server is currently too busy to support requests greater than %d for this database. For more information, see https://learn.microsoft.com/azure/azure-sql/database/resource-limits-logical-server. Otherwise, please try again later. - 64 + 18456 - A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 - The specified network name is no longer available.) (Microsoft SQL Server, Error: 64) + Login failed for user. (Using managed identity in Azure Sql Server throws 18456 for non-existent database instead of 4060.) - 20 - The instance of SQL Server you attempted to connect to does not support encryption. + 40143 + The service has encountered an error processing your request. Please try again. - 0 - A connection was successfully established with the server, but then an error occurred during the pre-login handshake. + 40197 + The service has encountered an error processing your request. Please try again. Error code %d. - -2 - Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. + 40501 + The service is currently busy. Retry the request after 10 seconds. Incident ID: %ls. Code: %d. - 207 - Invalid column name. + 40540 + The service has encountered an error processing your request. Please try again. - 18456 + 40613 - Login failed for user. (Using managed identity in Azure Sql Server throws 18456 for non-existent database instead of 4060.) + Database '%.*ls' on server '%.*ls' is not currently available. Please retry the connection later. If the problem persists, contact customer support, and provide them the session tracing ID of '%.*ls'. @@ -149,6 +135,20 @@ 42109 The SQL pool is warming up. Please try again. + + 49918 + Cannot process request. Not enough resources to process request. + + + 49919 + + Cannot process create or update request. Too many create or update operations in progress for subscription "%ld". + + + + 49920 + Cannot process request. Too many operations in progress for subscription "%ld". + @@ -286,10 +286,10 @@ - + - Gets a readonly replica of the transient error list. + The list of default transient error codes. - + diff --git a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs index 3dacfa4ceb..d4b1da2907 100644 --- a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs @@ -1971,9 +1971,8 @@ public sealed class SqlRetryLogicOption /// public sealed class SqlConfigurableRetryFactory { - /// - public static System.Collections.ObjectModel.ReadOnlyCollection s_defaultTransientErrors { get { throw null; } } - + /// + public static System.Collections.ObjectModel.ReadOnlyCollection DefaultTransientErrors { get { throw null; } } /// public static SqlRetryLogicBaseProvider CreateExponentialRetryProvider(SqlRetryLogicOption retryLogicOption) { throw null; } /// diff --git a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs index 1d480ad94d..8efec14569 100644 --- a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs @@ -1954,8 +1954,8 @@ public sealed class SqlRetryLogicOption /// public sealed class SqlConfigurableRetryFactory { - /// - public static System.Collections.ObjectModel.ReadOnlyCollection s_defaultTransientErrors { get { throw null; } } + /// + public static System.Collections.ObjectModel.ReadOnlyCollection DefaultTransientErrors { get { throw null; } } /// public static SqlRetryLogicBaseProvider CreateExponentialRetryProvider(SqlRetryLogicOption retryLogicOption) { throw null; } /// diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs index 32455c06df..c5bef99b8e 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs @@ -39,36 +39,36 @@ public sealed class SqlConfigurableRetryFactory private readonly static object s_syncObject = new(); /// Default known transient error numbers. - /// - public static readonly ReadOnlyCollection s_defaultTransientErrors + /// + public static readonly ReadOnlyCollection DefaultTransientErrors = new( [ + -2, // Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. + 0, // A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) + 20, // The instance of SQL Server you attempted to connect to does not support encryption. + 64, // A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 - The specified network name is no longer available.) + 207, // Invalid column name + 233, // A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) (Microsoft SQL Server, Error: 233) + 997, // A connection was successfully established with the server, but then an error occurred during the login process. (provider: Named Pipes Provider, error: 0 - Overlapped I/O operation is in progress) 1204, // The instance of the SQL Server Database Engine cannot obtain a LOCK resource at this time. Rerun your statement when there are fewer active users. Ask the database administrator to check the lock and memory configuration for this instance, or to check for long-running transactions. 1205, // Transaction (Process ID) was deadlocked on resources with another process and has been chosen as the deadlock victim. Rerun the transaction 1222, // Lock request time out period exceeded. - 49918, // Cannot process request. Not enough resources to process request. - 49919, // Cannot process create or update request. Too many create or update operations in progress for subscription "%ld". - 49920, // Cannot process request. Too many operations in progress for subscription "%ld". 4060, // Cannot open database "%.*ls" requested by the login. The login failed. 4221, // Login to read-secondary failed due to long wait on 'HADR_DATABASE_WAIT_FOR_TRANSITION_TO_VERSIONING'. The replica is not available for login because row versions are missing for transactions that were in-flight when the replica was recycled. The issue can be resolved by rolling back or committing the active transactions on the primary replica. Occurrences of this condition can be minimized by avoiding long write transactions on the primary. + 10060, // An error has occurred while establishing a connection to the server. When connecting to SQL Server, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) (Microsoft SQL Server, Error: 10060) + 10928, // Resource ID: %d. The %s limit for the database is %d and has been reached. For more information, see http://go.microsoft.com/fwlink/?LinkId=267637. + 10929, // Resource ID: %d. The %s minimum guarantee is %d, maximum limit is %d and the current usage for the database is %d. However, the server is currently too busy to support requests greater than %d for this database. For more information, see http://go.microsoft.com/fwlink/?LinkId=267637. Otherwise, please try again later. + 18456, // Using managed identity in Azure Sql Server throws 18456 for non-existent database instead of 4060. 40143, // The service has encountered an error processing your request. Please try again. - 40613, // Database '%.*ls' on server '%.*ls' is not currently available. Please retry the connection later. If the problem persists, contact customer support, and provide them the session tracing ID of '%.*ls'. + 40197, // The service has encountered an error processing your request. Please try again. Error code %d. 40501, // The service is currently busy. Retry the request after 10 seconds. Incident ID: %ls. Code: %d. 40540, // The service has encountered an error processing your request. Please try again. - 40197, // The service has encountered an error processing your request. Please try again. Error code %d. + 40613, // Database '%.*ls' on server '%.*ls' is not currently available. Please retry the connection later. If the problem persists, contact customer support, and provide them the session tracing ID of '%.*ls'. 42108, // Can not connect to the SQL pool since it is paused. Please resume the SQL pool and try again. 42109, // The SQL pool is warming up. Please try again. - 10929, // Resource ID: %d. The %s minimum guarantee is %d, maximum limit is %d and the current usage for the database is %d. However, the server is currently too busy to support requests greater than %d for this database. For more information, see http://go.microsoft.com/fwlink/?LinkId=267637. Otherwise, please try again later. - 10928, // Resource ID: %d. The %s limit for the database is %d and has been reached. For more information, see http://go.microsoft.com/fwlink/?LinkId=267637. - 10060, // An error has occurred while establishing a connection to the server. When connecting to SQL Server, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) (Microsoft SQL Server, Error: 10060) - 997, // A connection was successfully established with the server, but then an error occurred during the login process. (provider: Named Pipes Provider, error: 0 - Overlapped I/O operation is in progress) - 233, // A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) (Microsoft SQL Server, Error: 233) - 64, // A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 - The specified network name is no longer available.) - 20, // The instance of SQL Server you attempted to connect to does not support encryption. - 0, // A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) - -2, // Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. - 207, // invalid column name - 18456 // Using managed identity in Azure Sql Server throws 18456 for non-existent database instead of 4060. + 49918, // Cannot process request. Not enough resources to process request. + 49919, // Cannot process create or update request. Too many create or update operations in progress for subscription "%ld". + 49920 // Cannot process request. Too many operations in progress for subscription "%ld". ]); /// @@ -95,7 +95,7 @@ private static SqlRetryLogicBaseProvider InternalCreateRetryProvider(SqlRetryLog Debug.Assert(enumerator != null, $"The '{nameof(enumerator)}' mustn't be null."); var retryLogic = new SqlRetryLogic(retryLogicOption.NumberOfTries, enumerator, - (e) => TransientErrorsCondition(e, retryLogicOption.TransientErrors ?? s_defaultTransientErrors), + (e) => TransientErrorsCondition(e, retryLogicOption.TransientErrors ?? DefaultTransientErrors), retryLogicOption.AuthorizedSqlCondition); return new SqlRetryLogicProvider(retryLogic); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/RetryLogic/RetryLogicTestHelper.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/RetryLogic/RetryLogicTestHelper.cs index f6d7d563b7..3bbd3c3512 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/RetryLogic/RetryLogicTestHelper.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/RetryLogic/RetryLogicTestHelper.cs @@ -33,7 +33,7 @@ public static TheoryData GetConnectionStringA NumberOfTries = numberOfRetries, DeltaTime = deltaTime ?? TimeSpan.FromMilliseconds(10), MaxTimeInterval = maxInterval, - TransientErrors = transientErrorCodes ?? SqlConfigurableRetryFactory.s_defaultTransientErrors, + TransientErrors = transientErrorCodes ?? SqlConfigurableRetryFactory.DefaultTransientErrors, AuthorizedSqlCondition = RetryPreCondition(unauthorizedStatementRegex) }; @@ -81,7 +81,7 @@ private static IEnumerable GetRetryStrategiesTyped(Sq public static IEnumerable GetDefaultTransientErrorCodes(params int[] additionalCodes) { - var transientErrorCodes = new HashSet(SqlConfigurableRetryFactory.s_defaultTransientErrors); + var transientErrorCodes = new HashSet(SqlConfigurableRetryFactory.DefaultTransientErrors); foreach (int additionalCode in additionalCodes) { transientErrorCodes.Add(additionalCode); From 6652e9967278794df01950d6b1f0b02df1c22f78 Mon Sep 17 00:00:00 2001 From: Matthias_Huygelen Date: Thu, 22 Jan 2026 07:54:26 +0100 Subject: [PATCH 5/6] convert to property and add missing codes from xml to implementation --- .../Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs index c5bef99b8e..fd002e690a 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryFactory.cs @@ -40,7 +40,7 @@ public sealed class SqlConfigurableRetryFactory /// Default known transient error numbers. /// - public static readonly ReadOnlyCollection DefaultTransientErrors + public static ReadOnlyCollection DefaultTransientErrors { get; } = new( [ -2, // Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. @@ -55,6 +55,8 @@ public static readonly ReadOnlyCollection DefaultTransientErrors 1222, // Lock request time out period exceeded. 4060, // Cannot open database "%.*ls" requested by the login. The login failed. 4221, // Login to read-secondary failed due to long wait on 'HADR_DATABASE_WAIT_FOR_TRANSITION_TO_VERSIONING'. The replica is not available for login because row versions are missing for transactions that were in-flight when the replica was recycled. The issue can be resolved by rolling back or committing the active transactions on the primary replica. Occurrences of this condition can be minimized by avoiding long write transactions on the primary. + 10053, // Could not convert the data value due to reasons other than sign mismatch or overflow. + 10054, // The data value for one or more columns overflowed the type used by the provider. 10060, // An error has occurred while establishing a connection to the server. When connecting to SQL Server, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) (Microsoft SQL Server, Error: 10060) 10928, // Resource ID: %d. The %s limit for the database is %d and has been reached. For more information, see http://go.microsoft.com/fwlink/?LinkId=267637. 10929, // Resource ID: %d. The %s minimum guarantee is %d, maximum limit is %d and the current usage for the database is %d. However, the server is currently too busy to support requests greater than %d for this database. For more information, see http://go.microsoft.com/fwlink/?LinkId=267637. Otherwise, please try again later. From aba4f96c4fb2af9e04453291e1c2745e1162afa0 Mon Sep 17 00:00:00 2001 From: Matthias_Huygelen Date: Thu, 22 Jan 2026 08:49:09 +0100 Subject: [PATCH 6/6] typo --- .../Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml index f3c277e4e1..31ddd56e58 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml @@ -129,7 +129,7 @@ 42108 - Can not connect to the SQL pool since it is paused. Please resume the SQL pool and try again. + Cannot connect to the SQL pool since it is paused. Please resume the SQL pool and try again. 42109