Rediger

Del via


SqlFileStream Constructors

Definition

Initializes a new instance of the SqlFileStream class.

Overloads

SqlFileStream(String, Byte[], FileAccess)

Initializes a new instance of the SqlFileStream class.

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

Initializes a new instance of the SqlFileStream class.

Remarks

The following table lists the code access security (CAS) permissions that all callers in the stack must have to use the SqlFileStream constructors.

File access Permission
Read Read
Write Write
ReadWrite Read and Write

For more information about CAS, see Code Access Security and ADO.NET.

SqlFileStream(String, Byte[], FileAccess)

Source:
System.Data.SqlClient.notsupported.cs

Initializes a new instance of the SqlFileStream class.

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)

Parameters

path
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
Byte[]

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

access
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.IOSeek methods to move the handle position within the file to write or append new data.

Exceptions

path is a null reference, or transactionContext is null.

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.

The file cannot be found.

An I/O error occurred.

The caller does not have the required permission.

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

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.

NtCreateFile fails with error code set to ERROR_SHARING_VIOLATION.

Remarks

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

See also

Applies to

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

Source:
System.Data.SqlClient.notsupported.cs

Initializes a new instance of the SqlFileStream class.

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)

Parameters

path
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
Byte[]

The transaction context for the SqlFileStream object. When set to null, an implicit transaction will be used for the SqlFileStream object. Applications should return the byte array returned by calling the GET_FILESTREAM_TRANSACTION_CONTEXT method.

access
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.IOSeek methods to move the handle position within the file to write or append new data.

options
FileOptions

Specifies the option to use while opening the file. Supported FileOptions values are Asynchronous, WriteThrough, SequentialScan, and RandomAccess.

allocationSize
Int64

The allocation size to use while creating a file. If set to 0, the default value is used.

Exceptions

path is a null reference, or transactionContext is null.

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 call to NTCreateFile is not of type FILE_TYPE_DISK.

options contains an unsupported value.

The file cannot be found.

An I/O error occurred.

The caller does not have the required permission.

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

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.

NtCreateFile fails with error code set to ERROR_SHARING_VIOLATION.

Remarks

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

See also

Applies to