lat-ext-8.0) . For more information about
streaming, see [ SqlClient Streaming Support ](/en-
us/dotnet/framework/data/adonet/sqlclient-streaming-support) .

-or- 

A [ SqlDbType ](system.data.sqlclient.sqlparameter.sqldbtype?view=dotnet-plat-
ext-8.0#system-data-sqlclient-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 console application starts the process of retrieving XML data
asynchronously. While waiting for the results, this simple application sits in
a loop, investigating the [ IsCompleted
](system.iasyncresult.iscompleted?view=dotnet-plat-ext-8.0) property value.
Once the process has completed, the code retrieves the XML and displays its
contents.

    
    
    using System.Data.SqlClient;
    using System.Xml;
    
    class Class1
    {
        static void Main()
        {
            // This example is not terribly effective, but it proves a point.
            // The WAITFOR statement simply adds enough time to prove the
            // asynchronous nature of the command.
            string commandText =
                "WAITFOR DELAY '00:00:03';" +
                "SELECT Name, ListPrice FROM Production.Product " +
                "WHERE ListPrice < 100 " +
                "FOR XML AUTO, XMLDATA";
    
            RunCommandAsynchronously(commandText, GetConnectionString());
    
            Console.WriteLine("Press ENTER to continue.");
            Console.ReadLine();
        }
    
        private static void RunCommandAsynchronously(
            string commandText, string c