Bug in SqlCommand.ExecuteNonQueryAsync()
See original GitHub issueWhen calling await command.ExecuteReturnValueAsync() inside a using block I get an exception saying a task was cancelled.
If I call await Task.Delay(100) before the end of the using scope, the call succeeds.
Similarly, if the call is to a stored procedure with a return value, I get a NullReferenceException if I attempt to read the return value without delaying first.
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
c# - Trapping and throwing errors when using ...
This is new territory for me. I would like to achieve this (pseudocode) pattern Connection.OpenAsync().Success( cmd.ExecuteNonQueryAsync().
Read more >SqlCommand.ExecuteNonQueryAsync(CancellationToken ...
An asynchronous version of ExecuteNonQuery(), which executes a Transact-SQL statement against the connection and returns the number of rows affected.
Read more >70111: Asynchronous functions in MySql connector/Net ...
First, all async operations in the data provider should be implemented overriding the base async methods, that is, DbConnection.OpenAsync, ...
Read more >SqlCommand.ExecuteNonQueryAsync, System.Data. ...
The SqlCommand ExecuteNonQueryAsync method is utilized to execute SQL statements that don't return any results, such as INSERT, UPDATE, DELETE, etc.
Read more >Is this SqlConnection / SqlCommand async wrapper both ...
First() : null; return new TaskResult<T>(tResult, exception); }).Result; }. How is all this different from just task.Result ?
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes -
The problem seemingly disappeared on its own. I haven’t been able to figure out why - the exact same code that failed previously suddenly worked with no changes. This was true without updating the packages. I don’t know if it was some weird condition on the server that caused it, or if it was something else, maybe a platform update.
Anyway, I am no longer able to reproduce, and I’ve actively tried to reproduce it. Previously I could reproduce at will.
Skaff deg Outlook for Androidhttps://aka.ms/ghei36
From: Cheena Malhotra notifications@github.com Sent: Wednesday, January 13, 2021 9:30:07 PM To: dotnet/SqlClient SqlClient@noreply.github.com Cc: Christian Ruud cru@develop.no; Mention mention@noreply.github.com Subject: Re: [dotnet/SqlClient] Bug in SqlCommand.ExecuteNonQueryAsync() (#536)
@christian-ruudhttps://github.com/christian-ruud
Do you have any update on this issue?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/dotnet/SqlClient/issues/536#issuecomment-759720956, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AO2MAHA4KPTDXXL3S6CY62LSZX7E7ANCNFSM4MO4X3AA.
This is getting really weird.
I copied the failing code into LinqPad to create a simple piece of code you could test, but so far I’ve been unable to reproduce the error in LinqPad.
However, I still get the exception in the original codebase . In this case that’s Blazor Server -> .net standard 2.1 dll -> .net standard 2.1 dll. I haven’t tried the PR, as I want to predicably reproduce with a code snippet first.
Essentially
command.ExecuteNonQuery()works both in production code and code snippetawait commandExecuteNonQueryAsync()works in code snippet but fails in production code.The code is otherwise identical.
It seems like it could be dependant on load, perhaps? Or maybe the database? How much data is in the table? Maybe it’s different for a web project somehow?
I’ll keep trying to figure out the circumstances under which the error is triggered. I can think of the following things to try, would be great if you have any suggestions: