大网数据广告活动
磁盘与文件系统

JetCreateDatabase2 Function

· 52CE 我爱测

Learn more about: JetCreateDatabase2 Function

Applies to: Windows | Windows Server

JetCreateDatabase2 Function

The JetCreateDatabase2 function creates and attaches a database file to be used with the ESE database engine with a maximum database size specified. Calling JetCreateDatabase2 with cpgDatabaseSizeMax set to zero is identical to calling JetCreateDatabase with szConnect set to NULL. Currently up to seven databases can be created per instance.

    JET_ERR JET_API JetCreateDatabase2(
      __in          JET_SESID sesid,
      __in          const tchar* szFilename,
      __in          const unsigned long cpgDatabaseSizeMax,
      __out         JET_DBID* pdbid,
      __in          JET_GRBIT grbit
    );

Parameters

sesid

The database session context to use for the API call.

szFilename

The name of the database to be created.

cpgDatabaseSizeMax

The maximum size, in database pages, for the database. The default database page size is 4 kilobytes, and can be changed with JetSetSystemParameter prior to creating a database.

Passing zero means that there is no maximum enforced by the database engine.

pdbid

Pointer to a buffer that, on a successful call, contains the identifier of the database. On failure, the value is undefined.

grbit

A group of bits specifying zero or more of the following options.

Value Meaning
JET_bitDbOverwriteExisting By default, if <a href="gg269212(v=exchg.10).md">JetCreateDatabase</a> or JetCreateDatabase2 is called and the database already exists, the API call will fail and the original database will not be overwritten. JET_bitDbOverwriteExisting changes this behavior, and the old database will be overwritten with a new one. Windows XP and later.
JET_bitDbRecoveryOff JET_bitDbRecoveryOff turns off logging. Setting this bit loses the ability to replay log files and recover the database to a consistent usable state after a catastrophic event.
JET_bitDbShadowingOff Setting JET_bitDbShadowingOff will disable the duplication of some internal database structures (shadowing). The duplication of these structures is done for resiliency, so setting JET_bitDbShadowingOff will remove that resiliency.

Return Value

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.

Return code Description
JET_errSuccess The operation completed successfully.
JET_errDatabaseDuplicate The database named in szFilename already exists. When this error is returned, the database does not get attached.
JET_errDatabaseInUse Can be returned if exclusive access was requested, but could not be granted, or if another session has already opened the database exclusively.
JET_errDatabaseInvalidPages Returned when cpgDatabaseSizeMax is larger than the maximum number of pages allowed in a database. The current maximum is 2147483646 (0x7ffffffe).
JET_errDatabaseInvalidPath An invalid path was given in szFilename. szFilename must be non-NULL. By default, szFilename must point to a directory that exists. The path will be created if JET_paramCreatePathIfNotExist is set (See <a href="gg294044(v=exchg.10).md">JetSetSystemParameter</a>).
JET_errDatabaseLocked Indicates that another session has already opened the database exclusively (using JET_bitDbExclusive).
JET_errDatabaseNotFound The database was not previously attached (See <a href="gg294074(v=exchg.10).md">JetAttachDatabase</a>).
JET_errDatabaseSharingViolation The database file has already been attached by a different session.
JET_errInTransaction An attempt was made to create a database while in a transaction.
JET_errInvalidDatabase An attempt was made to open a file that is not a valid database file.
JET_errOneDatabasePerSession An attempt was made to open more than one database, and JET_paramOneDatabasePerSession was set. See <a href="gg294139(v=exchg.10).md">System Parameters</a>.
JET_errOutOfMemory The system ran low on resources.
JET_errTooManyAttachedDatabases Only a finite number of database can be attached per instance. The limit is currently seven databases per instance.
JET_wrnDatabaseAttached A nonfatal warning indicating that the database file has already been attached by this session.
JET_wrnFileOpenReadOnly JET_wrnFileOpenReadOnly indicates that the file was attached read-only, but <a href="gg269212(v=exchg.10).md">JetCreateDatabase</a> did not pass JET_bitDbReadOnly. The database is still opened with read-only access.
Remarks

If the database specified in szFilename exists and JET_bitDbOverwriteExisting was not passed in, the API call will fail. If JET_bitDbOverwriteExisting was passed in, the old database file will be deleted first.

If the API creates a database file and then hits another error, it will clean up and delete the file.

JetCreateDatabase2 will implicitly open the database. It is not necessary to subsequently call JetOpenDatabase.

Requirements
Requirement Value
Client Requires Windows Vista, Windows XP, or Windows 2000 Professional.
Server Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
Header Declared in Esent.h.
Library Use ESENT.lib.
DLL Requires ESENT.dll.
Unicode Implemented as JetCreateDatabase2W (Unicode) and JetCreateDatabase2A (ANSI).
See Also

Extensible Storage Engine Files
JET_ERR
JET_DBID
JET_GRBIT
JET_SESID
JetAttachDatabase
JetCloseDatabase
JetCreateDatabase
JetOpenDatabase
JetSetSystemParameter
System Parameters

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 04/11/2016
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

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

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