SqlFileStream 類別

定義

公開使用 FILESTREAM 資料行屬性儲存為位元組序列的 SQL Server 資料。Exposes SQL Server data that is stored with the FILESTREAM column attribute as a sequence of bytes.

public ref class SqlFileStream sealed : System::IO::Stream
public sealed class SqlFileStream : System.IO.Stream
type SqlFileStream = class
    inherit Stream
Public NotInheritable Class SqlFileStream
Inherits Stream
繼承

備註

類別是用來varbinary(max)處理以 SQL Server 2008 資料庫中的 FILESTREAM 屬性所儲存的資料。 SqlFileStreamThe SqlFileStream class is used to work with varbinary(max) data stored with the FILESTREAM attribute in a SQL Server 2008 database. 您必須安裝 .NET Framework 3.5 SP1 (或更新版本),才能SqlFileStream用來處理 FILESTREAM 資料。You must install the .NET Framework 3.5 SP1 (or later) to use SqlFileStream to work with FILESTREAM data.

在資料varbinary(max)行上指定 FILESTREAM 屬性會導致 SQL Server 將資料儲存在本機 NTFS 檔案系統中,而不是存放在資料庫檔案中。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 語句提供伺服器內的資料操作功能,而 Win32 檔案系統介面則提供資料的資料流程存取。Transact-SQL statements provide data manipulation capabilities within the server, and Win32 file system interfaces provide streaming access to the data.

注意

儲存在 FILESTREAM 資料行中的個別檔案無法直接從 NTFS 檔案系統開啟。Individual files stored in a FILESTREAM column cannot be opened directly from the NTFS file system. 資料流程處理 FILESTREAM 資料僅適用于 SQL Server 交易的內容。Streaming FILESTREAM data works only in the context of a SQL Server transaction.

SqlFileStream類別衍生Stream自類別,這表示來自一些任意資料來源(例如檔案或記憶體區塊)之位元組序列的抽象概念。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. 您可以藉由將資料流程中的資料傳輸至資料結構(例如位元組陣列)來讀取 FILESTREAM。You can read from a FILESTREAM by transferring data from a stream into a data structure such as an array of bytes. 您可以藉由將資料從資料結構傳送到資料流程,來寫入 FILESTREAM。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.

如需概念性檔和程式碼範例,請參閱FILESTREAM 資料For conceptual documentation and code examples, see FILESTREAM Data.

如需有關在 SQL Server 上設定 FILESTREAM 資料的檔,請參閱《 SQL Server 2008 線上叢書》中的設計和執行 Filestream 儲存For documentation about setting up and configuring FILESTREAM data on SQL Server, see Designing and Implementing FILESTREAM Storage in SQL Server 2008 Books Online.

建構函式

SqlFileStream(String, Byte[], FileAccess)

初始化 SqlFileStream 類別的新執行個體。Initializes a new instance of the SqlFileStream class.

SqlFileStream(String, Byte[], FileAccess, FileOptions, Int64)

初始化 SqlFileStream 類別的新執行個體。Initializes a new instance of the SqlFileStream class.

屬性

CanRead

取得表示目前資料流是否支援讀取的值。Gets a value indicating whether the current stream supports reading.

CanSeek

取得表示目前資料流是否支援搜尋的值。Gets a value indicating whether the current stream supports seeking.

CanTimeout

取得指出目前資料流是否會逾時的值。Gets a value indicating whether the current stream can time out.

CanWrite

取得表示目前資料流是否支援寫入的值。Gets a value indicating whether the current stream supports writing.

Length

取得值,這個值表示目前資料流的長度 (以位元組為單位)。Gets a value indicating the length of the current stream in bytes.

Name

取得傳遞至建構函式之 SqlFileStream 的邏輯路徑。Gets the logical path of the SqlFileStream passed to the constructor.

Position

取得或設定在目前資料流中的位置。Gets or sets the position within the current stream.

ReadTimeout

取得或設定值 (以毫秒為單位),這個值決定在逾時前資料流將嘗試讀取多長時間。Gets or sets a value, in milliseconds, that determines how long the stream will attempt to read before timing out.

TransactionContext

取得或設定這個 SqlFileStream 物件的交易內容。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.

方法

BeginRead(Byte[], Int32, Int32, AsyncCallback, Object)

開始非同步的讀取作業。Begins an asynchronous read operation.

BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object)

開始非同步的寫入作業。Begins an asynchronous write operation.

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.

(繼承來源 Stream)
CopyTo(Stream)

從目前資料流讀取位元組,並將其寫入另一個資料流中。Reads the bytes from the current stream and writes them to another stream.

(繼承來源 Stream)
CopyTo(Stream, Int32)

使用指定的緩衝區大小,從目前資料流讀取所有位元組,並將其寫入另一個資料流中。Reads the bytes from the current stream and writes them to another stream, using a specified buffer size.

(繼承來源 Stream)
CopyToAsync(Stream)

以非同步的方式從目前資料流讀取所有位元組,並將其寫入另一個資料流中。Asynchronously reads the bytes from the current stream and writes them to another stream.

(繼承來源 Stream)
CopyToAsync(Stream, CancellationToken)

使用指定的取消權杖,以非同步的方式從目前資料流讀取位元組,並將其寫入另一個資料流。Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified cancellation token.

(繼承來源 Stream)
CopyToAsync(Stream, Int32)

使用指定的緩衝區大小,以非同步的方式從目前資料流讀取所有位元組,並將其寫入另一個資料流中。Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size.

(繼承來源 Stream)
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.

(繼承來源 Stream)
CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(繼承來源 MarshalByRefObject)
CreateWaitHandle()

配置 WaitHandle 物件。Allocates a WaitHandle object.

(繼承來源 Stream)
Dispose()

釋放 Stream 所使用的所有資源。Releases all resources used by the Stream.

(繼承來源 Stream)
Dispose(Boolean)

釋放 Stream 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the Stream and optionally releases the managed resources.

(繼承來源 Stream)
DisposeAsync()

以非同步方式釋放 Stream 使用的不受控資源。Asynchronously releases the unmanaged resources used by the Stream.

(繼承來源 Stream)
EndRead(IAsyncResult)

等候暫止的非同步讀取完成。Waits for the pending asynchronous read to complete.

EndWrite(IAsyncResult)

結束非同步的寫入作業。Ends an asynchronous write operation.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
Finalize()

確認釋出資源,並在記憶體回收行程再利用 SqlFileStream 時執行其他清除作業。Ensures that resources are freed and other cleanup operations are performed when the garbage collector reclaims the SqlFileStream.

Flush()

清除這個資料流的所有緩衝區,並造成任何緩衝資料都寫入基礎裝置。clears all buffers for this stream and causes any buffered data to be written to the underlying device.

FlushAsync()

以非同步的方式清除這個資料流的所有緩衝區,並造成所有緩衝資料都寫入基礎裝置。Asynchronously clears all buffers for this stream and causes any buffered data to be written to the underlying device.

(繼承來源 Stream)
FlushAsync(CancellationToken)

以非同步的方式清除這個資料流的所有緩衝區,造成所有緩衝資料都寫入基礎裝置,並且監視取消要求。Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests.

(繼承來源 Stream)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(繼承來源 MarshalByRefObject)
ObjectInvariant()

提供 Contract 的支援。Provides support for a Contract.

(繼承來源 Stream)
Read(Byte[], Int32, Int32)

從目前的資料流讀取位元組序列,並依讀取的位元組數將資料流中的位置往前移。Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

Read(Span<Byte>)

當在衍生類別中覆寫時,自目前資料流讀取一連串的位元組,並依所讀取的位元組數目進階資料流中的位置。When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

(繼承來源 Stream)
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.

(繼承來源 Stream)
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.

(繼承來源 Stream)
ReadAsync(Memory<Byte>, 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.

(繼承來源 Stream)
ReadByte()

從資料流讀取一個位元組,並將資料流的位置推進一個位元組;如果在資料流末端,則傳回 -1。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.

Seek(Int64, SeekOrigin)

設定目前資料流位置。Sets the position within the current stream.

SetLength(Int64)

設定目前資料流的長度。Sets the length of the current stream.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
Write(Byte[], Int32, Int32)

將位元組序列寫入至目前的資料流,並依寫入的位元組數將資料流中目前的位置往前移。Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

Write(ReadOnlySpan<Byte>)

在衍生類別中覆寫時,將一連串的位元組寫入目前的資料流,並且由這個資料流中目前的位置前移寫入的位元組數目。When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

(繼承來源 Stream)
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.

(繼承來源 Stream)
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.

(繼承來源 Stream)
WriteAsync(ReadOnlyMemory<Byte>, 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.

(繼承來源 Stream)
WriteByte(Byte)

寫入一個位元組至資料流的目前位置,並將資料流位置推進一個位元組。Writes a byte to the current position in the stream and advances the position within the stream by one byte.

明確介面實作

IDisposable.Dispose()

釋放 Stream 所使用的所有資源。Releases all resources used by the Stream.

(繼承來源 Stream)

擴充方法

CopyToAsync(Stream, PipeWriter, CancellationToken)

使用取消語彙基元,以非同步的方式從 Stream 讀取位元組,並將其寫入指定的 PipeWriterAsynchronously reads the bytes from the Stream and writes them to the specified PipeWriter, using a cancellation token.

AsInputStream(Stream)

將適用於 Windows 市集應用程式的 .NET 中的受控資料流轉換成 Windows 執行階段中的輸入資料流。Converts a managed stream in the .NET for Windows Store apps to an input stream in the Windows Runtime.

AsOutputStream(Stream)

將適用於 Windows 市集應用程式的 .NET 中的受控資料流轉換成 Windows 執行階段中的輸出資料流。Converts a managed stream in the .NET for Windows Store apps to an output stream in the Windows Runtime.

AsRandomAccessStream(Stream)

將指定的資料流轉換為隨機存取資料流。Converts the specified stream to a random access stream.

適用於

另請參閱