Cancelling an async SqlClient operation throws SqlException, not TaskCanceledException · Issue #26 · dotnet/SqlClient

PHOTO EMBED

Sat Apr 23 2022 23:03:06 GMT+0000 (Coordinated Universal Time)

Saved by @iamsingularity

catch (SqlException ex) when (cancellationToken.IsCancellationRequested && ex.Number == 0 && ex.State == 0 && ex.Class == 11)
{
    throw new OperationCanceledException(cancellationToken);
}
content_copyCOPY

https://github.com/dotnet/SqlClient/issues/26