SqlDataReader.GetStream Method (Int32)

.NET Framework (current version)

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Retrieves binary, image, varbinary, UDT, and variant data types as a Stream.

Namespace:   System.Data.SqlClient
Assembly:  System.Data (in System.Data.dll)

public override Stream GetStream(
	int i


Type: System.Int32

The zero-based column ordinal.

Return Value

Type: System.IO.Stream

A stream object.

Exception Condition

The connection drops or is closed during the data retrieval.

The SqlDataReader is closed during the data retrieval.

There is no data ready to be read (for example, the first Read hasn't been called, or returned false).

Tried to read a previously-read column in sequential mode.

There was an asynchronous operation in progress. This applies to all Get* methods when running in sequential mode, as they could be called while reading a stream.


Trying to read a column that does not exist.


The returned type was not one of the types below:

  • binary

  • image

  • varbinary

  • udt

ReadTimeout defaults to the value of CommandTimeout; but you can modify ReadTimeout via GetStream.

Null values will be returned as an empty (zero bytes) Stream.

GetBytes will raise an InvalidOperationException exception when used on an object returned by GetStream when SequentialAccess is in effect.

SqlException exceptions raised from Stream are thrown as IOException exceptions; check the inner exception for the SqlException.

The following Stream members are not available for objects returned by GetStream:

  • BeginWrite

  • EndWrite

  • Length

  • Position

  • Seek

  • SetLength

  • Write

  • WriteByte

  • WriteTimeout

When the connection property ContextConnection=true, GetStream only supports synchronous data retrieval for both sequential (SequentialAccess) and non-sequential (Default) access.

For more information, see SqlClient Streaming Support.

.NET Framework
Available since 4.5
Return to top