Files
sqltoolsservice/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/RetryPolicy.NetworkConnectivityErrorStrategy.cs
Mitchell Sternke f2a5654a20 Feature/reliable connection (#44)
* Initial commit of reliable connection port

* Made ReliableSqlConnection inherit from DbConnection instead of IDbConnection

* Cleanup

* Fixed autocomplete service to use reliable connection

* Fix copyright headers

* Renamed ConnectResponse.Server to ServerInfo

* Removed unused using

* Addressing code review feedback
2016-09-13 18:10:26 -07:00

44 lines
1.7 KiB
C#

//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Data.SqlClient;
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
{
internal abstract partial class RetryPolicy
{
/// <summary>
/// Provides the error detection logic for temporary faults that are commonly found in SQL Azure.
/// The same errors CAN occur on premise also, but they are not seen as often.
/// </summary>
internal sealed class NetworkConnectivityErrorDetectionStrategy : ErrorDetectionStrategyBase, IErrorDetectionStrategy
{
private static NetworkConnectivityErrorDetectionStrategy instance = new NetworkConnectivityErrorDetectionStrategy();
public static NetworkConnectivityErrorDetectionStrategy Instance
{
get { return instance; }
}
protected override bool CanRetrySqlException(SqlException sqlException)
{
// Enumerate through all errors found in the exception.
bool foundRetryableError = false;
foreach (SqlError err in sqlException.Errors)
{
RetryPolicyUtils.AppendThrottlingDataIfIsThrottlingError(sqlException, err);
if (!RetryPolicyUtils.IsRetryableNetworkConnectivityError(err.Number))
{
// If any error is not retryable then cannot retry
return false;
}
foundRetryableError = true;
}
return foundRetryableError;
}
}
}
}