Export (0) Print
Expand All

SqlFileStream Constructor (String, Byte[], FileAccess)

Initializes a new instance of the SqlFileStream class.

Namespace:  System.Data.SqlTypes
Assembly:  System.Data (in System.Data.dll)

public SqlFileStream(
	string path,
	byte[] transactionContext,
	FileAccess access
)

Parameters

path
Type: System.String

The logical path to the file. The path can be retrieved by using the Transact-SQL Pathname function on the underlying FILESTREAM column in the table.

transactionContext
Type: System.Byte[]

The transaction context for the SqlFileStream object. Applications should return the byte array returned by calling the GET_FILESTREAM_TRANSACTION_CONTEXT method.

access
Type: System.IO.FileAccess

The access mode to use when opening the file. Supported FileAccess enumeration values are Read, Write, and ReadWrite.

When using FileAccess.Read, the SqlFileStream object can be used to read all of the existing data.

When using FileAccess.Write, SqlFileStream points to a zero byte file. Existing data will be overwritten when the object is closed and the transaction is committed.

When using FileAccess.ReadWrite, the SqlFileStream points to a file which has all the existing data in it. The handle is positioned at the beginning of the file. You can use one of the System.IO Seek methods to move the handle position within the file to write or append new data.

ExceptionCondition
ArgumentNullException

path is a null reference, or transactionContext is null.

ArgumentOutOfRangeException

path is an empty string (""), contains only white space, or contains one or more invalid characters.

path begins with "\\.\", for example "\\.\PHYSICALDRIVE0 ".

The handle returned by the call to NTCreateFile is not of type FILE_TYPE_DISK.

options contains an unsupported value.

FileNotFoundException

The file cannot be found.

IOException

An I/O error occurred.

SecurityException

The caller does not have the required permission.

DirectoryNotFoundException

The specified path is invalid, such as being on an unmapped drive.

UnauthorizedAccessException

The access requested is not permitted by the operating system for the specified path. This occurs when Write or ReadWrite access is specified, and the file or directory is set for read-only access.

InvalidOperationException

NtCreateFile fails with error code set to ERROR_SHARING_VIOLATION.

If an exception is thrown, any open transactions should be rolled back. Otherwise, data loss can occur.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5 SP1, 3.0 SP2, 2.0 SP2

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft