Hey all,
I currently have a method that runs a sql query and returns a dataset. I need to convert this over into a method that supports cancellation.

From what I’ve read, I need to pass the method a cancellationtoken, then elsewhere I can cancel the token at any time and it will allow me to cancel the sql query. I’m discovering that adapter.Fill does not support a cancellation token, so I need to use sqlcommand.ExecuteReaderAsync(CancellationToken).
Is there a “good” way to convert the method to support cancellation? The sql query could be any different type (select, insert, update, delete) and the output should always be a DataSet.
This API is oddly still lacking: https://github.com/dotnet/runtime/issues/22109
You might be able to fork https://github.com/voloda/AsyncDataAdapter/ to add cancellation to that one.
Does this https://stackoverflow.com/questions/24738417/canceling-sql-server-query-with-cancellationtoken offer any help?
Have a look at this, it should help; https://stackoverflow.com/a/25545312
Use an ORM like Entity Framework Core.
EF would be way too much for such a simple problem. What about EF were you thinking about? Maybe there’s something about your suggestion that’s worth noting here.
C# devs
null reference exceptions

source