|
| 1 | +// Copyright (C) 2020 Xtensive LLC. |
| 2 | +// All rights reserved. |
| 3 | +// For conditions of distribution and use, see license. |
| 4 | +// Created by: Denis Krjuchkov |
| 5 | +// Created: 2020.04.10 |
| 6 | + |
| 7 | +using System; |
| 8 | +using System.Collections.Generic; |
| 9 | +using System.Data.SqlClient; |
| 10 | +using Xtensive.Core; |
| 11 | + |
| 12 | +namespace Xtensive.Sql.Drivers.SqlServer |
| 13 | +{ |
| 14 | + internal static class InternalHelpers |
| 15 | + { |
| 16 | + /// <summary> |
| 17 | + /// This API supports the Entity Framework Core infrastructure and is not intended to be used |
| 18 | + /// directly from your code. This API may change or be removed in future releases. |
| 19 | + /// </summary> |
| 20 | + public static bool ShouldRetryOn(Exception ex) |
| 21 | + { |
| 22 | + ArgumentValidator.EnsureArgumentNotNull(ex, "ex"); |
| 23 | + SqlException sqlException = ex as SqlException; |
| 24 | + if (sqlException != null) { |
| 25 | + foreach (SqlError err in sqlException.Errors) { |
| 26 | + switch (err.Number) { |
| 27 | + // SQL Error Code: 49920 |
| 28 | + // Cannot process request. Too many operations in progress for subscription "%ld". |
| 29 | + // The service is busy processing multiple requests for this subscription. |
| 30 | + // Requests are currently blocked for resource optimization. Query sys.dm_operation_status for operation status. |
| 31 | + // Wait until pending requests are complete or delete one of your pending requests and retry your request later. |
| 32 | + case 49920: |
| 33 | + // SQL Error Code: 49919 |
| 34 | + // Cannot process create or update request. Too many create or update operations in progress for subscription "%ld". |
| 35 | + // The service is busy processing multiple create or update requests for your subscription or server. |
| 36 | + // Requests are currently blocked for resource optimization. Query sys.dm_operation_status for pending operations. |
| 37 | + // Wait till pending create or update requests are complete or delete one of your pending requests and |
| 38 | + // retry your request later. |
| 39 | + case 49919: |
| 40 | + // SQL Error Code: 49918 |
| 41 | + // Cannot process request. Not enough resources to process request. |
| 42 | + // The service is currently busy.Please retry the request later. |
| 43 | + case 49918: |
| 44 | + // SQL Error Code: 41839 |
| 45 | + // Transaction exceeded the maximum number of commit dependencies. |
| 46 | + case 41839: |
| 47 | + // SQL Error Code: 41325 |
| 48 | + // The current transaction failed to commit due to a serializable validation failure. |
| 49 | + case 41325: |
| 50 | + // SQL Error Code: 41305 |
| 51 | + // The current transaction failed to commit due to a repeatable read validation failure. |
| 52 | + case 41305: |
| 53 | + // SQL Error Code: 41302 |
| 54 | + // The current transaction attempted to update a record that has been updated since the transaction started. |
| 55 | + case 41302: |
| 56 | + // SQL Error Code: 41301 |
| 57 | + // Dependency failure: a dependency was taken on another transaction that later failed to commit. |
| 58 | + case 41301: |
| 59 | + // SQL Error Code: 40613 |
| 60 | + // Database XXXX on server YYYY is not currently available. Please retry the connection later. |
| 61 | + // If the problem persists, contact customer support, and provide them the session tracing ID of ZZZZZ. |
| 62 | + case 40613: |
| 63 | + // SQL Error Code: 40501 |
| 64 | + // The service is currently busy. Retry the request after 10 seconds. Code: (reason code to be decoded). |
| 65 | + case 40501: |
| 66 | + // SQL Error Code: 40197 |
| 67 | + // The service has encountered an error processing your request. Please try again. |
| 68 | + case 40197: |
| 69 | + // SQL Error Code: 10929 |
| 70 | + // Resource ID: %d. The %s minimum guarantee is %d, maximum limit is %d and the current usage for the database is %d. |
| 71 | + // However, the server is currently too busy to support requests greater than %d for this database. |
| 72 | + // For more information, see http://go.microsoft.com/fwlink/?LinkId=267637. Otherwise, please try again. |
| 73 | + case 10929: |
| 74 | + // SQL Error Code: 10928 |
| 75 | + // Resource ID: %d. The %s limit for the database is %d and has been reached. For more information, |
| 76 | + // see http://go.microsoft.com/fwlink/?LinkId=267637. |
| 77 | + case 10928: |
| 78 | + // SQL Error Code: 10060 |
| 79 | + // A network-related or instance-specific error occurred while establishing a connection to SQL Server. |
| 80 | + // The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server |
| 81 | + // is configured to allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed |
| 82 | + // because the connected party did not properly respond after a period of time, or established connection failed |
| 83 | + // because connected host has failed to respond.)"} |
| 84 | + case 10060: |
| 85 | + // SQL Error Code: 10054 |
| 86 | + // A transport-level error has occurred when sending the request to the server. |
| 87 | + // (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.) |
| 88 | + case 10054: |
| 89 | + // SQL Error Code: 10053 |
| 90 | + // A transport-level error has occurred when receiving results from the server. |
| 91 | + // An established connection was aborted by the software in your host machine. |
| 92 | + case 10053: |
| 93 | + // SQL Error Code: 1205 |
| 94 | + // Deadlock |
| 95 | + case 1205: |
| 96 | + // SQL Error Code: 233 |
| 97 | + // The client was unable to establish a connection because of an error during connection initialization process before login. |
| 98 | + // Possible causes include the following: the client tried to connect to an unsupported version of SQL Server; |
| 99 | + // the server was too busy to accept new connections; or there was a resource limitation (insufficient memory or maximum |
| 100 | + // allowed connections) on the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by |
| 101 | + // the remote host.) |
| 102 | + case 233: |
| 103 | + // SQL Error Code: 121 |
| 104 | + // The semaphore timeout period has expired |
| 105 | + case 121: |
| 106 | + // SQL Error Code: 64 |
| 107 | + // A connection was successfully established with the server, but then an error occurred during the login process. |
| 108 | + // (provider: TCP Provider, error: 0 - The specified network name is no longer available.) |
| 109 | + case 64: |
| 110 | + // DBNETLIB Error Code: 20 |
| 111 | + // The instance of SQL Server you attempted to connect to does not support encryption. |
| 112 | + case 20: |
| 113 | + return true; |
| 114 | + // This exception can be thrown even if the operation completed succesfully, so it's safer to let the application fail. |
| 115 | + // DBNETLIB Error Code: -2 |
| 116 | + // Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated. |
| 117 | + //case -2: |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + return false; |
| 122 | + } |
| 123 | + |
| 124 | + return ex is TimeoutException; |
| 125 | + } |
| 126 | + } |
| 127 | +} |
0 commit comments