SqlFileStream 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 SqlFileStream 类的新实例。
重载
| 名称 | 说明 |
|---|---|
| SqlFileStream(String, Byte[], FileAccess) |
初始化 SqlFileStream 类的新实例。 |
| SqlFileStream(String, Byte[], FileAccess, FileOptions, Int64) |
初始化 SqlFileStream 类的新实例。 |
注解
下表列出了堆栈中的所有调用方必须使用 SqlFileStream 构造函数的代码访问安全性(CAS)权限。
| 文件访问 | 许可 |
|---|---|
| 读取 | Read |
| 写入 | Write |
| 读写 | Read 和 Write |
有关 CAS 的详细信息,请参阅 Code Access Security and ADO.NET。
SqlFileStream(String, Byte[], FileAccess)
初始化 SqlFileStream 类的新实例。
public:
SqlFileStream(System::String ^ path, cli::array <System::Byte> ^ transactionContext, System::IO::FileAccess access);
public SqlFileStream(string path, byte[] transactionContext, System.IO.FileAccess access);
new System.Data.SqlTypes.SqlFileStream : string * byte[] * System.IO.FileAccess -> System.Data.SqlTypes.SqlFileStream
Public Sub New (path As String, transactionContext As Byte(), access As FileAccess)
参数
- path
- String
文件的逻辑路径。 可以使用表中基础 FILESTREAM 列上的 Transact-SQL Pathname 函数检索路径。
- transactionContext
- Byte[]
对象的 SqlFileStream 事务上下文。 应用程序应返回通过调用 GET_FILESTREAM_TRANSACTION_CONTEXT 方法返回的字节数组。
- access
- FileAccess
打开文件时要使用的访问模式。 支持的 FileAccess 枚举值为 Read, Write以及 ReadWrite。
使用 FileAccess.Read时, SqlFileStream 该对象可用于读取所有现有数据。
使用 FileAccess.Write时, SqlFileStream 指向零字节文件。 当对象关闭并提交事务时,将覆盖现有数据。
使用 FileAccess.ReadWrite时,指向 SqlFileStream 包含其中所有现有数据的文件。 句柄位于文件的开头。 可以使用其中 System.IOSeek 一种方法移动文件中的句柄位置以写入或追加新数据。
例外
path 为 null 引用,或 transactionContext 为 null。
path 为空字符串(“”),仅包含空格,或包含一个或多个无效字符。
-或-
path 以“\\.\”开头,例如“\\.\PHYSICALDRIVE0”。
-或-
对 NTCreateFile 的调用返回的句柄的类型不是FILE_TYPE_DISK。
找不到该文件。
出现 I/O 错误。
调用方没有所需的权限。
指定的 path 值无效,例如位于未映射的驱动器上。
操作系统不允许针对指定路径请求的访问。 指定写入或 ReadWrite 访问时,会发生这种情况,并且文件或目录设置为只读访问。
NtCreateFile 失败,错误代码设置为ERROR_SHARING_VIOLATION。
注解
如果引发异常,则应回滚任何打开的事务。 否则,可能会发生数据丢失。
另请参阅
适用于
SqlFileStream(String, Byte[], FileAccess, FileOptions, Int64)
初始化 SqlFileStream 类的新实例。
public:
SqlFileStream(System::String ^ path, cli::array <System::Byte> ^ transactionContext, System::IO::FileAccess access, System::IO::FileOptions options, long allocationSize);
public SqlFileStream(string path, byte[] transactionContext, System.IO.FileAccess access, System.IO.FileOptions options, long allocationSize);
new System.Data.SqlTypes.SqlFileStream : string * byte[] * System.IO.FileAccess * System.IO.FileOptions * int64 -> System.Data.SqlTypes.SqlFileStream
Public Sub New (path As String, transactionContext As Byte(), access As FileAccess, options As FileOptions, allocationSize As Long)
参数
- path
- String
文件的逻辑路径。 可以使用表中基础 FILESTREAM 列上的 Transact-SQL Pathname 函数检索路径。
- transactionContext
- Byte[]
对象的 SqlFileStream 事务上下文。 如果设置为 null,则隐式事务将用于 SqlFileStream 对象。 应用程序应返回通过调用 GET_FILESTREAM_TRANSACTION_CONTEXT 方法返回的字节数组。
- access
- FileAccess
打开文件时要使用的访问模式。 支持的 FileAccess 枚举值为 Read, Write以及 ReadWrite。
使用 FileAccess.Read时, SqlFileStream 该对象可用于读取所有现有数据。
使用 FileAccess.Write时, SqlFileStream 指向零字节文件。 当对象关闭并提交事务时,将覆盖现有数据。
使用 FileAccess.ReadWrite时,指向 SqlFileStream 包含其中所有现有数据的文件。 句柄位于文件的开头。 可以使用其中 System.IOSeek 一种方法移动文件中的句柄位置以写入或追加新数据。
- options
- FileOptions
指定打开文件时要使用的选项。 支持的 FileOptions 值为 Asynchronous、 WriteThrough、 SequentialScan和 RandomAccess。
- allocationSize
- Int64
创建文件时要使用的分配大小。 如果设置为 0,则使用默认值。
例外
path 为 null 引用,或 transactionContext 为 null。
path 为空字符串(“”),仅包含空格,或包含一个或多个无效字符。
path 以“\\.\”开头,例如“\\.\PHYSICALDRIVE0”。
调用 NTCreateFile 返回的句柄的类型不是FILE_TYPE_DISK。
options 包含不受支持的值。
找不到该文件。
出现 I/O 错误。
调用方没有所需的权限。
指定的 path 值无效,例如位于未映射的驱动器上。
操作系统不允许针对指定路径请求的访问。 指定写入或 ReadWrite 访问时,会发生这种情况,并且文件或目录设置为只读访问。
NtCreateFile 失败,错误代码设置为ERROR_SHARING_VIOLATION。
注解
如果引发异常,则应回滚任何打开的事务。 否则,可能会发生数据丢失。