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
继承

注解

类用于处理与 SQL Server 2008 数据库中的 FILESTREAM 属性一起存储的数据。varbinary(max) 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.

备注

不能直接从 NTFS 文件系统打开存储在 FILESTREAM 列中的单个文件。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)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。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 占用的非托管资源,还可以另外再释放托管资源。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()

检索控制此实例的生存期策略的当前生存期服务对象。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 的浅表副本。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()

返回一个表示当前对象的 string。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.

适用于

另请参阅