question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug in SqlCommand.ExecuteNonQueryAsync()

See original GitHub issue

When 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:closed
  • Created 3 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
christian-ruudcommented, Jan 13, 2021

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.

1reaction
christian-ruudcommented, Sep 2, 2020

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 snippet await 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:

  • I’ll try making a console app instead of using LinqPad, in case it gives me different results.
  • I’ll try using a blazor app to reproduce in case it gives me different result
  • I’ll try making the calls against the actual production database.
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found