kann die Ausführung nicht fortsetzen, weil der Session in dem Tötungsstatus. weggeworfen werden.
Code: Select all
internal class Program
{
private const string CnnStringFormat = "Data Source = localhost; Initial Catalog = dbtest; User ID = sa; Password=aaaaaa;Encrypt=True;TrustServerCertificate=True";
private static SqlConnection s_generalConnection = new SqlConnection(CnnStringFormat);
static void Main(string[] args)
{
SqlCommand comando = new SqlCommand("spGetLoadTest") { CommandType = System.Data.CommandType.StoredProcedure };
var options = new SqlRetryLogicOption()
{
NumberOfTries = 5,
MaxTimeInterval = TimeSpan.FromSeconds(60),
DeltaTime = TimeSpan.FromSeconds(15),
TransientErrors = new List { -1, -2, 0, 109, 233, 997, 1222, 10060, -2146232060, 596 }
};
var provider = SqlConfigurableRetryFactory.CreateExponentialRetryProvider(options);
provider.Retrying += (object s, SqlRetryingEventArgs e) =>
{
NotificaRetry(e);
var cmd = s as SqlCommand;
cmd.Connection.Close();
cmd.Connection.Open();
cmd.CommandTimeout = 3000;
};
s_generalConnection.RetryLogicProvider = provider;
s_generalConnection.Open();
comando.Connection = s_generalConnection;
comando.RetryLogicProvider = provider;
SqlDataReader leitor = null;
try
{
comando.CommandTimeout = 300;
leitor = comando.ExecuteReader();
var count = leitor.Depth;
var colunas = leitor.FieldCount;
}
catch (Exception ex)
{
Console.WriteLine("ERROR: " + ex.Message);
}
}
private static void NotificaRetry(SqlRetryingEventArgs e)
{
int attempts = e.RetryCount + 1;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"attempt {attempts} - current delay time:{e.Delay} \n");
Console.WriteLine($"error: {e.Exceptions[e.RetryCount-1].Message} \n");
Console.ForegroundColor = ConsoleColor.DarkGray;
}
}