This topic has not yet been rated - Rate this topic

SqlFileStream Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Exposes SQL Server data that is stored with the FILESTREAM column attribute as a sequence of bytes.

System.Object
  System.MarshalByRefObject
    System.IO.Stream
      System.Data.SqlTypes.SqlFileStream

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

public sealed class SqlFileStream : Stream

The SqlFileStream type exposes the following members.

  Name Description
Public method SqlFileStream(String, Byte[], FileAccess) Initializes a new instance of the SqlFileStream class.
Public method SqlFileStream(String, Byte[], FileAccess, FileOptions, Int64) Initializes a new instance of the SqlFileStream class.
Top
  Name Description
Public property CanRead Gets a value indicating whether the current stream supports reading. (Overrides Stream.CanRead.)
Public property CanSeek Gets a value indicating whether the current stream supports seeking. (Overrides Stream.CanSeek.)
Public property CanTimeout Gets a value indicating whether the current stream can time out. (Overrides Stream.CanTimeout.)
Public property CanWrite Gets a value indicating whether the current stream supports writing. (Overrides Stream.CanWrite.)
Public property Length Gets a value indicating the length of the current stream in bytes. (Overrides Stream.Length.)
Public property Name Gets the logical path of the SqlFileStream passed to the constructor.
Public property Position Gets or sets the position within the current stream. (Overrides Stream.Position.)
Public property ReadTimeout Gets or sets a value, in milliseconds, that determines how long the stream will attempt to read before timing out. (Overrides Stream.ReadTimeout.)
Public property TransactionContext Gets or sets the transaction context for this SqlFileStream object.
Public property WriteTimeout Gets or sets a value, in milliseconds, that determines how long the stream will attempt to write before timing out. (Overrides Stream.WriteTimeout.)
Top
  Name Description
Public method BeginRead Begins an asynchronous read operation. (Overrides Stream.BeginRead(Byte[], Int32, Int32, AsyncCallback, Object).)
Public method BeginWrite Begins an asynchronous write operation. (Overrides Stream.BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object).)
Public method Close Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream. Instead of calling this method, ensure that the stream is properly disposed. (Inherited from Stream.)
Public method CopyTo(Stream) Reads the bytes from the current stream and writes them to another stream. (Inherited from Stream.)
Public method CopyTo(Stream, Int32) Reads the bytes from the current stream and writes them to another stream, using a specified buffer size. (Inherited from Stream.)
Public method CopyToAsync(Stream) Asynchronously reads the bytes from the current stream and writes them to another stream. (Inherited from Stream.)
Public method CopyToAsync(Stream, Int32) Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size. (Inherited from Stream.)
Public method CopyToAsync(Stream, Int32, CancellationToken) Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size and cancellation token. (Inherited from Stream.)
Public method CreateObjRef Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Protected method CreateWaitHandle Obsolete. Allocates a WaitHandle object. (Inherited from Stream.)
Public method Dispose() Releases all resources used by the Stream. (Inherited from Stream.)
Protected method Dispose(Boolean) Releases the unmanaged resources used by the Stream and optionally releases the managed resources. (Inherited from Stream.)
Public method EndRead Waits for the pending asynchronous read to complete. (Overrides Stream.EndRead(IAsyncResult).)
Public method EndWrite Ends an asynchronous write operation. (Overrides Stream.EndWrite(IAsyncResult).)
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Flush clears all buffers for this stream and causes any buffered data to be written to the underlying device. (Overrides Stream.Flush().)
Public method FlushAsync() Asynchronously clears all buffers for this stream and causes any buffered data to be written to the underlying device. (Inherited from Stream.)
Public method FlushAsync(CancellationToken) Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests. (Inherited from Stream.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetLifetimeService Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method InitializeLifetimeService Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method MemberwiseClone(Boolean) Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Protected method ObjectInvariant Infrastructure. Obsolete. Provides support for a Contract. (Inherited from Stream.)
Public method Read Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read. (Overrides Stream.Read(Byte[], Int32, Int32).)
Public method ReadAsync(Byte[], Int32, Int32) Asynchronously reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read. (Inherited from Stream.)
Public method ReadAsync(Byte[], Int32, Int32, CancellationToken) Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests. (Inherited from Stream.)
Public method ReadByte Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream. (Overrides Stream.ReadByte().)
Public method Seek Sets the position within the current stream. (Overrides Stream.Seek(Int64, SeekOrigin).)
Public method SetLength Sets the length of the current stream. (Overrides Stream.SetLength(Int64).)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method Write Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. (Overrides Stream.Write(Byte[], Int32, Int32).)
Public method WriteAsync(Byte[], Int32, Int32) Asynchronously writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. (Inherited from Stream.)
Public method WriteAsync(Byte[], Int32, Int32, CancellationToken) Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests. (Inherited from Stream.)
Public method WriteByte Writes a byte to the current position in the stream and advances the position within the stream by one byte. (Overrides Stream.WriteByte(Byte).)
Top
  Name Description
Public Extension Method AsInputStream Converts a managed stream in the .NET APIs for Metro style apps to an input stream in the Windows Runtime. (Defined by WindowsRuntimeStreamExtensions.)
Public Extension Method AsOutputStream Converts a managed stream in the .NET APIs for Metro style apps to an output stream in the Windows Runtime. (Defined by WindowsRuntimeStreamExtensions.)
Top

The SqlFileStream class is used to work with varbinary(max) data stored with the FILESTREAM attribute in a SQL Server 2008 database. You must install the .NET Framework 3.5 SP1 (or later) to use System.Data.SqlTypes.SqlFileStream to work with FILESTREAM data.

Specifying the FILESTREAM attribute on a varbinary(max) column causes SQL Server to store the data in the local NTFS file system instead of in the database file. Transact-SQL statements provide data manipulation capabilities within the server, and Win32 file system interfaces provide streaming access to the data.

Note Note

Individual files stored in a FILESTREAM column cannot be opened directly from the NTFS file system. Streaming FILESTREAM data works only in the context of a SQL Server transaction.

The SqlFileStream class is derived from the Stream class, which represents an abstraction of a sequence of bytes from some arbitrary data source such as a file or a block of memory. You can read from a FILESTREAM by transferring data from a stream into a data structure such as an array of bytes. You can write to a FILESTREAM by transferring the data from a data structure into a stream. You can also seek within the stream, which allows you to query and modify data at the current position within the stream.

For conceptual documentation and code examples, see FILESTREAM Data in SQL Server 2008 (ADO.NET).

For documentation about setting up and configuring FILESTREAM data on SQL Server, see Designing and Implementing FILESTREAM Storage in SQL Server 2008 Books Online.

.NET Framework

Supported in: 4.5, 4, 3.5 SP1, 3.0 SP2, 2.0 SP2

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8 Release Preview, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 SP2, Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)