Skip to content

Instantly share code, notes, and snippets.

@explorer14
Last active January 14, 2020 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save explorer14/c5bbb83281f480ee82c4a8220a1a6d80 to your computer and use it in GitHub Desktop.
Save explorer14/c5bbb83281f480ee82c4a8220a1a6d80 to your computer and use it in GitHub Desktop.
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