2 out of 2 rated this helpful - Rate this topic

SqlCommand.BeginExecuteReader Method

Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this SqlCommand, and retrieves one or more result sets from the server.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

  Name Description
Public method BeginExecuteReader() Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this SqlCommand, and retrieves one or more result sets from the server.
Public method BeginExecuteReader(CommandBehavior) Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this SqlCommand using one of the CommandBehavior values.
Public method BeginExecuteReader(AsyncCallback, Object) Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this SqlCommand and retrieves one or more result sets from the server, given a callback procedure and state information.
Public method BeginExecuteReader(AsyncCallback, Object, CommandBehavior) Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this SqlCommand, using one of the CommandBehavior values, and retrieving one or more result sets from the server, given a callback procedure and state information.
Top
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
BeginExecuteReader method and CommandTimeouts
I'd like to point out a bug that I came accross very recently while trying to use Async Sql Methods. Here is the bug:
"Per the MSDN documentation, all asynchronous ADO.NET SqlCommand operations ignore the CommandTimeout property setting and will execute until the
asynchronous operation is complete.

I have found several cases where this is not true. In BeginExecuteNonQuery and BeginExecuteReader, if a threshold of Rows counts, print statement or transaction commits is crossed a TDS message is reported by SQL server. After this threshold is crossed, the AsyncCallback is invoked even though the operation is not complete. After the callback is triggered, the call to EndExecuteNonQuery blocks for whatever the value of "CommandTimeout" is set to. This is contrary to the documentation on MSDN.

When testing with transactions, I empirically found this was 286 or more transaction in two different test environments. I tested against both local and remote SQL instances. This appears to be a direct side-effect of chaining the callback invocation to the overlapped IO response read in the TDS Parser.

The possible workarounds are to set the CommandTimeout to 0 or abandon the Asynchronous pattern all together. Neither option is desirable because it would amount waiting indefinitely in an threadpool thread in a high-load service application."URL: http://connect.microsoft.com/VisualStudio/feedback/details/632055/asynchronous-methods-in-sqlcommand-fail-to-wait-for-command-completion-in-several-circumstances