-
-
Save explorer14/c5bbb83281f480ee82c4a8220a1a6d80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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