ient-sqlparameter-sqldbtype) other than **Char** ,
**NChar** , **NVarChar** , **VarChar** , or **Xml** was used when [ Value
](system.data.sqlclient.sqlparameter.value?view=dotnet-plat-ext-8.0#system-
data-sqlclient-sqlparameter-value) was set to [ TextReader
](system.io.textreader?view=dotnet-plat-ext-8.0) .

-or- 

A [ SqlDbType ](system.data.sqlclient.sqlparameter.sqldbtype?view=dotnet-plat-
ext-8.0#system-data-sqlclient-sqlparameter-sqldbtype) other than **Xml** was
used when [ Value ](system.data.sqlclient.sqlparameter.value?view=dotnet-plat-
ext-8.0#system-data-sqlclient-sqlparameter-value) was set to [ XmlReader
](system.xml.xmlreader?view=dotnet-plat-ext-8.0) .

[ SqlException ](system.data.sqlclient.sqlexception?view=dotnet-plat-ext-8.0)

Any error that occurred while executing the command text.

-or- 

A timeout occurred during a streaming operation. For more information about
streaming, see [ SqlClient Streaming Support ](/en-
us/dotnet/framework/data/adonet/sqlclient-streaming-support) .

[ InvalidOperationException ](system.invalidoperationexception?view=dotnet-
plat-ext-8.0)

The name/value pair "Asynchronous Processing=true" was not included within the
connection string defining the connection for this [ SqlCommand
](system.data.sqlclient.sqlcommand?view=dotnet-plat-ext-8.0) .

-or- 

The [ SqlConnection ](system.data.sqlclient.sqlconnection?view=dotnet-plat-
ext-8.0) closed or dropped during a streaming operation. For more information
about streaming, see [ SqlClient Streaming Support ](/en-
us/dotnet/framework/data/adonet/sqlclient-streaming-support) .

[ IOException ](system.io.ioexception?view=dotnet-plat-ext-8.0)

An error occurred in a [ Stream ](system.io.stream?view=dotnet-plat-ext-8.0) ,
[ XmlReader ](system.xml.xmlreader?view=dotnet-plat-ext-8.0) or [ TextReader
](system.io.textreader?view=dotnet-plat-ext-8.0) object during a streaming
operation. For more information about streaming, see [ SqlClient Streaming
Support ](/en-us/dotnet/framework/data/adonet/sqlclient-streaming-support) .

[ ObjectDisposedException ](system.objectdisposedexception?view=dotnet-plat-
ext-8.0)

The [ Stream ](system.io.stream?view=dotnet-plat-ext-8.0) , [ XmlReader
](system.xml.xmlreader?view=dotnet-plat-ext-8.0) or [ TextReader
](system.io.textreader?view=dotnet-plat-ext-8.0) object was closed during a
streaming operation. For more information about streaming, see [ SqlClient
Streaming Support ](/en-us/dotnet/framework/data/adonet/sqlclient-streaming-
support) .

###  Examples

The following Windows application demonstrates the use of the [
BeginExecuteReader
](system.data.sqlclient.sqlcommand.beginexecutereader?view=dotnet-plat-
ext-8.0) method, executing a Transact-SQL statement that includes a delay of a
few seconds (emulating a long-running command). Because the sample executes
the command asynchronously, the form remains responsive while awaiting the
results. This example passes the executing [ SqlCommand
](system.data.sqlclient.sqlcommand?view=dotnet-plat-ext-8.0) object as the `
stateObject ` parameter; doing so makes it simple to retrieve the [ SqlCommand
](system.data.sqlclient.sqlcommand?view=dotnet-plat-ext-8.0) object from
within the callback procedure, so that the code can call the [
EndExecuteReader
](system.data.sqlclient.sqlcommand.endexecutereader?view=dotnet-plat-ext-8.0)
method corresponding to the initial call to [ BeginExecuteReader
](system.data.sqlclient.sqlcommand.beginexecutereader?view=dotnet-plat-
ext-8.0) .

This example demonstrates many important techniques. This includes calling a
method that interacts with the form from a separate thread. In addition, this
example demonstrates how you must block users from executing a command
multiple times concurrently, and how you must make sure that the form does not
close before the callback procedure is called.

To set up this example, create a new Windows application. Put a [ Button
](system.windows.forms.button?view=dotnet-plat-ext-8.0) control, a [
Dat