0

I'm writing my app with NET Standard 2.1 and MySql (NuGet pack MySql.Data). The MySqlException doesn't have the property IsTransient so I can't recognize if the exception is temporary. How can I manage this? Is there a list of error code that are transient? I can't find it.

Thanks

1 Answers1

0

If switching NuGet packages is an option for you, the MySqlConnector package (disclaimer: I'm the lead author) implements this property: https://github.com/mysql-net/MySqlConnector/issues/849

Otherwise, you could borrow its logic:

public static bool IsTransient(MySqlException ex) => (MySqlErrorCode) ex.Code
    is MySqlErrorCode.ConnectionCountError
    or MySqlErrorCode.LockDeadlock
    or MySqlErrorCode.LockWaitTimeout
    or MySqlErrorCode.UnableToConnectToHost
    or MySqlErrorCode.XARBDeadlock
Bradley Grainger
  • 27,458
  • 4
  • 91
  • 108