Files
sqltoolsservice/src/Microsoft.SqlTools.ManagedBatchParser/ReliableConnection/RetryPolicy.NetworkConnectivityErrorStrategy.cs
David Shiflet 9d140b53f3 Switch Tools Service to new SMO and Microsoft.Data.SqlClient driver (#865)
* switch to ambient props and targets files

* build against Microsoft.Data.SqlClient

* build tests

* fix test bug

* temporarily add SMO nuget to the repo

* update to released Microsoft.Data package
2019-09-17 17:51:19 -04: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 Microsoft.Data.SqlClient;
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
{
public 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>
public sealed class NetworkConnectivityErrorDetectionStrategy : ErrorDetectionStrategyBase
{
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;
}
}
}
}