Export (0) Print
Expand All

SqlFileStream Class

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.

  NameDescription
Public methodSqlFileStream(String, Byte[], FileAccess)Initializes a new instance of the SqlFileStream class.
Public methodSqlFileStream(String, Byte[], FileAccess, FileOptions, Int64)Initializes a new instance of the SqlFileStream class.
Top

  NameDescription
Public propertyCanReadGets a value indicating whether the current stream supports reading. (Overrides Stream.CanRead.)
Public propertyCanSeekGets a value indicating whether the current stream supports seeking. (Overrides Stream.CanSeek.)
Public propertyCanTimeoutGets a value indicating whether the current stream can time out. (Overrides Stream.CanTimeout.)
Public propertyCanWriteGets a value indicating whether the current stream supports writing. (Overrides Stream.CanWrite.)
Public propertyLengthGets a value indicating the length of the current stream in bytes. (Overrides Stream.Length.)
Public propertyNameGets the logical path of the SqlFileStream passed to the constructor.
Public propertyPositionGets or sets the position within the current stream. (Overrides Stream.Position.)
Public propertyReadTimeoutGets or sets a value, in milliseconds, that determines how long the stream will attempt to read before timing out. (Overrides Stream.ReadTimeout.)
Public propertyTransactionContextGets or sets the transaction context for this SqlFileStream object.
Public propertyWriteTimeoutGets or sets a value, in milliseconds, that determines how long the stream will attempt to write before timing out. (Overrides Stream.WriteTimeout.)
Top

  NameDescription
Public methodBeginReadBegins an asynchronous read operation. (Overrides Stream.BeginRead(Byte[], Int32, Int32, AsyncCallback, Object).)
Public methodBeginWriteBegins an asynchronous write operation. (Overrides Stream.BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object).)
Public methodCloseCloses the current stream and releases any resources (such as sockets and file handles) associated with the current stream. (Inherited from Stream.)
Public methodCopyTo(Stream)Reads the bytes from the current stream and writes them to the destination stream. (Inherited from Stream.)
Public methodCopyTo(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.)
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Protected methodCreateWaitHandle Obsolete. Allocates a WaitHandle object. (Inherited from Stream.)
Public methodDispose()Releases all resources used by the Stream. (Inherited from Stream.)
Protected methodDispose(Boolean)Releases the unmanaged resources used by the Stream and optionally releases the managed resources. (Inherited from Stream.)
Public methodEndReadWaits for the pending asynchronous read to complete. (Overrides Stream.EndRead(IAsyncResult).)
Public methodEndWriteEnds an asynchronous write operation. (Overrides Stream.EndWrite(IAsyncResult).)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodFlushclears all buffers for this stream and causes any buffered data to be written to the underlying device. (Overrides Stream.Flush().)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Protected methodObjectInvariantInfrastructure. Provides support for a Contract. (Inherited from Stream.)
Public methodReadReads 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 methodReadByteReads 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 methodSeekSets the position within the current stream. (Overrides Stream.Seek(Int64, SeekOrigin).)
Public methodSetLengthSets the length of the current stream. (Overrides Stream.SetLength(Int64).)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodWriteWrites 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 methodWriteByteWrites a byte to the current position in the stream and advances the position within the stream by one byte. (Overrides Stream.WriteByte(Byte).)
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.

NoteNote

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, 3.5 SP1, 3.0 SP2, 2.0 SP2

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft