MsiOpenDatabaseA function (msiquery.h)
The MsiOpenDatabase function opens a database file for data access. This function returns a handle that should be closed using MsiCloseHandle.
Syntax
UINT MsiOpenDatabaseA(
[in] LPCSTR szDatabasePath,
[in] LPCSTR szPersist,
[out] MSIHANDLE *phDatabase
);
Parameters
[in] szDatabasePath
Specifies the full path or relative path to the database file.
[in] szPersist
Receives the full path to the file or the persistence mode. You can use the szPersist parameter to direct the persistent output to a new file or to specify one of the following predefined persistence modes.
[out] phDatabase
Pointer to the location of the returned database handle.
Return value
The MsiOpenDatabase function returns the following values:
Remarks
To make and save changes to a database first open the database in transaction (MSIDBOPEN_TRANSACT), create (MSIDBOPEN_CREATE or MSIDBOPEN_CREATEDIRECT), or direct (MSIDBOPEN_DIRECT) mode. After making the changes, always call MsiDatabaseCommit before closing the database handle. MsiDatabaseCommit flushes all buffers.
Always call MsiDatabaseCommit on a database that has been opened in direct mode (MSIDBOPEN_DIRECT or MSIDBOPEN_CREATEDIRECT) before closing the database's handle. Failure to do this may corrupt the database.
Because MsiOpenDatabase initiates database access, it cannot be used with a running installation.
Note that it is recommended to use variables of type PMSIHANDLE because the installer closes PMSIHANDLE objects as they go out of scope, whereas you must close MSIHANDLE objects by calling MsiCloseHandle. For more information see Use PMSIHANDLE instead of HANDLE section in the Windows Installer Best Practices.
Note
The msiquery.h header defines MsiOpenDatabase as an alias that automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that is not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows Installer 5.0 on Windows Server 2012, Windows 8, Windows Server 2008 R2 or Windows 7. Windows Installer 4.0 or Windows Installer 4.5 on Windows Server 2008 or Windows Vista. Windows Installer on Windows Server 2003 or Windows XP |
Target Platform | Windows |
Header | msiquery.h |
Library | Msi.lib |
DLL | Msi.dll |