Skip to content

Instantly share code, notes, and snippets.

@explorer14

explorer14/ClearPools.cs Secret

Last active Jan 14, 2020
Embed
What would you like to do?
policies.Execute(() =>
{
using (var conn = new MySqlConnection(ConnectionString))
{
try
{
conn.Open();
conn.Insert(new Record { Id = i + 1, Name = $"Aman {i + 1}" });
Log.Logger.Information(
"Inserted row with id {id} successfully!",
i + 1);
}
catch (MySqlException mysqlEx)
{
if (mysqlEx.IsFailoverException())
{
Log.Logger.Warning(
"Clearing current connection pool because an exception {@exception} occurred",
new
{
Msg = mysqlEx.Message,
Number = mysqlEx.Number,
HR = mysqlEx.HResult
});
// for this call to do anything, the idle pool should have non-zero connections
// which it will after the connection is disposed. This increases the likelihood
// of retries succeeding.
MySqlConnection.ClearPool(conn);
}
throw mysqlEx;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.