SqlFileStream Class
Exposes SQL Server data that is stored with the FILESTREAM column attribute as a sequence of bytes.
Assembly: System.Data (in System.Data.dll)
The SqlFileStream type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | SqlFileStream(String, Byte[], FileAccess) | Initializes a new instance of the SqlFileStream class. |
![]() | SqlFileStream(String, Byte[], FileAccess, FileOptions, Int64) | Initializes a new instance of the SqlFileStream class. |
| Name | Description | |
|---|---|---|
![]() | CanRead | Gets a value indicating whether the current stream supports reading. (Overrides Stream.CanRead.) |
![]() | CanSeek | Gets a value indicating whether the current stream supports seeking. (Overrides Stream.CanSeek.) |
![]() | CanTimeout | Gets a value indicating whether the current stream can time out. (Overrides Stream.CanTimeout.) |
![]() | CanWrite | Gets a value indicating whether the current stream supports writing. (Overrides Stream.CanWrite.) |
![]() | Length | Gets a value indicating the length of the current stream in bytes. (Overrides Stream.Length.) |
![]() | Name | Gets the logical path of the SqlFileStream passed to the constructor. |
![]() | Position | Gets or sets the position within the current stream. (Overrides Stream.Position.) |
![]() | ReadTimeout | Gets or sets a value, in milliseconds, that determines how long the stream will attempt to read before timing out. (Overrides Stream.ReadTimeout.) |
![]() | TransactionContext | Gets or sets the transaction context for this SqlFileStream object. |
![]() | WriteTimeout | Gets or sets a value, in milliseconds, that determines how long the stream will attempt to write before timing out. (Overrides Stream.WriteTimeout.) |
| Name | Description | |
|---|---|---|
![]() | BeginRead | Begins an asynchronous read operation. (Overrides Stream.BeginRead(Byte[], Int32, Int32, AsyncCallback, Object).) |
![]() | BeginWrite | Begins an asynchronous write operation. (Overrides Stream.BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object).) |
![]() | Close | Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream. (Inherited from Stream.) |
![]() | CopyTo(Stream) | Reads the bytes from the current stream and writes them to the destination stream. (Inherited from Stream.) |
![]() | CopyTo(Stream, Int32) | Reads all the bytes from the current stream and writes them to a destination stream, using a specified buffer size. (Inherited from Stream.) |
![]() | 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.) |
![]() | CreateWaitHandle | Obsolete. Allocates a WaitHandle object. (Inherited from Stream.) |
![]() | Dispose() | Releases all resources used by the Stream. (Inherited from Stream.) |
![]() | Dispose(Boolean) | Releases the unmanaged resources used by the Stream and optionally releases the managed resources. (Inherited from Stream.) |
![]() | EndRead | Waits for the pending asynchronous read to complete. (Overrides Stream.EndRead(IAsyncResult).) |
![]() | EndWrite | Ends an asynchronous write operation. (Overrides Stream.EndWrite(IAsyncResult).) |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | Flush | clears all buffers for this stream and causes any buffered data to be written to the underlying device. (Overrides Stream.Flush().) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetLifetimeService | Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | InitializeLifetimeService | Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.) |
![]() | MemberwiseClone() | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.) |
![]() | ObjectInvariant | Infrastructure. Provides support for a Contract. (Inherited from Stream.) |
![]() | 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).) |
![]() | 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().) |
![]() | Seek | Sets the position within the current stream. (Overrides Stream.Seek(Int64, SeekOrigin).) |
![]() | SetLength | Sets the length of the current stream. (Overrides Stream.SetLength(Int64).) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
![]() | 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).) |
![]() | 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).) |
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 |
|---|
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.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
