Last modified: January 09, 2012
Applies to: Windows | Windows Server
The JetOpenFile function opens an attached database, database patch file, or transaction log file of an active instance for the purpose of performing a streaming fuzzy backup. The data from these files can subsequently be read through the returned handle using JetReadFile. The returned handle must be closed using JetCloseFile. An external backup of the instance must have been previously initiated using JetBeginExternalBackup.
JET_ERR JET_API JetOpenFile( __in const tchar* szFileName, __out JET_HANDLE* phfFile, __out unsigned long* pulFileSizeLow, __out unsigned long* pulFileSizeHigh );
The relative or absolute path to an attached database, database patch file, or transaction log file managed by the instance that will be read for backup.
The output buffer that receives a handle to the file to be read.
The output buffer that receives the least significant 32 bits of the size of the file.
The output buffer that receives the most significant 32 bits of the size of the file.
This function returns the JET_ERR datatype with one of the following return codes. For more information about the possible ESE errors, see Extensible Storage Engine Errors and Error Handling Parameters.
The operation completed successfully.
The operation failed because the current external backup has been aborted by a call to JetStopBackup. This error will only be returned by Windows XP and later releases.
It is not possible to complete the operation because all activity on the instance associated with the session has ceased as a result of a call to JetStopService.
The operation failed because it could not open the requested file due to a sharing violation or insufficient privileges.
The operation failed because it could not open the requested file because it could not be found at the specified path. This error will only be returned by Windows 2000.
It is not possible to complete the operation because the instance associated with the session has encountered a fatal error that requires that access to all data be revoked to protect the integrity of that data. This error will only be returned by Windows XP and later releases.
The backup operation failed because it was called out of sequence.
One of the parameters provided contained an unexpected value or contained a value that did not make sense when combined with the value of another parameter. This can happen for JetOpenFile when:
The operation failed because the specified path could not be found.
The requested file could not be opened for backup because it could not be found. This error will only be returned by Windows XP and later releases.
The operation failed because no external backup is in progress.
It is not possible to complete the operation because the instance associated with the session has not been initialized yet.
The operation failed because not enough memory could be allocated to complete it. JetOpenFile will return JET_errOutOfMemory if an attempt is made to open another file before the previous file opened using JetOpenFile has been closed by JetCloseFile. Only one outstanding file handle is currently supported.
The operation failed because an attempt was made to use the engine in legacy mode (Windows 2000 compatibility mode) where only one instance is supported when in fact multiple instances already exist.
It is not possible to complete the operation because the instance associated with the session is being shut down. JET_errRestoreInProgress It is not possible to complete the operation because a restore operation is in progress on the instance associated with the session.
On success, a handle to the requested file will be returned. If the handle is for a database file, that database file will be prepared for streaming backup which may result in the creation of a database patch file in the same location as the database file. The database patch file has the exact same path and filename as the database file, but has a .PAT extension. The size of the file will also be returned.
On failure, the state of the output buffers will be undefined. A database patch file may be temporarily created on disk and any existing file at the patch file location may be deleted. The failure will result in the cancellation of the entire backup process for the instance. On Windows XP and later releases, the backup will not be canceled if an attempt was made to backup a database that was not attached to the instance at the time of the call.
Warning For security reasons, it is important to note that JetOpenFile does not verify that the requested file path is associated with the set of files that should be backed up for the instance. As a result, it is possible to use this function to access any file that can be opened by the current security context of the thread. It is imperative that the application restrict the paths passed to this function to a known set of good file paths or a disclosure of information attack could be made possible.
The handle and file size output buffers are required to be present. If they are not present then the engine will crash because the output buffer parameters are not validated.
At this time, only one file can be open for backup at any one time.
JetOpenFile does not assert the backup privilege prior to opening the requested file.
The size of the file to be read as reported by this function may not match the size of the file on disk. On Windows XP and later releases, extra information may be appended to a database file which is used by the database engine during a restore operation. As such, the application should only rely on the file size returned by JetOpenFile or on the actual number of bytes of data returned by JetReadFile.
Requires Windows Vista, Windows XP, or Windows 2000 Professional.
Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
Declared in Esent.h.
Implemented as JetOpenFileW (Unicode) and JetOpenFileA (ANSI).