大网数据广告活动
安装更新与部署

Installer.OpenDatabase method

· 52CE 我爱测

The OpenDatabase method of the Installer object opens an existing database or creates a new one, returning a Database object. It generates an error if the Database object cannot be successfully created and opened.

The OpenDatabase method of the Installer object opens an existing database or creates a new one, returning a Database object. It generates an error if the Database object cannot be successfully created and opened.

Syntax

Installer.OpenDatabase(
  name,
  openMode
)

Parameters

name

Required string that contains the path name of the database. If an empty string is supplied, a temporary database is created that is not persisted.

openMode

A parameter from the following list or a string that contains the path name of the new output database file that is to be written to upon commit.

Parameter Meaning
msiOpenDatabaseModeReadOnly 0 Opens a database read-only, no persistent changes.
msiOpenDatabaseModeTransact 1 Opens a database read/write in transaction mode.
msiOpenDatabaseModeDirect 2 Opens a database direct read/write without transaction.
msiOpenDatabaseModeCreate 3 Creates a new database, transact mode read/write.
msiOpenDatabaseModeCreateDirect 4 Creates a new database, direct mode read/write.
msiOpenDatabaseModeListScript 5 Opens a database to view advertise script files, such as the files generated by the CreateAdvertiseScript method.
msiOpenDatabaseModePatchFile 32 Adds this flag to indicate a patch file.

Return value

A Database object that represents the existing or new installer database that was opened.

Remarks

When a database is opened as the output of another database, the summary information stream of the output database is actually a read-only mirror of the original database and thus cannot be changed. Additionally, it is not persisted with the database. To create or modify the summary information for the output database it must be closed and reopened.

To make and save changes to a database first open the database in transaction (msiOpenDatabaseModeTransact), create (msiOpenDatabaseModeCreate or msiOpenDatabaseModeCreateDirect), or direct (msiOpenDatabaseModeDirect) mode. After making the changes, always call the Commit method before closing the database handle. The Commit method flushes all buffers.

Always call the Commit method on a database that has been opened in direct mode (msiOpenDatabaseModeDirect or msiOpenDatabaseModeCreateDirect) before closing the database. Failure to do this may corrupt the database.

Because the OpenDatabase method initiates database access, it cannot be used with a running installation.

If the method fails, you can obtain extended error information by using the LastErrorRecord method.

Requirements

Requirement Value
Version 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
DLL Msi.dll
IID IID_IInstaller is defined as 000C1090-0000-0000-C000-000000000046

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。