JetCreateDatabase Function

Applies to: Windows | Windows Server

JetCreateDatabase Function

The JetCreateDatabase function creates and attaches a database file to be used with the ESE database engine. 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 JetCreateDatabase(
      __in          JET_SESID sesid,
      __in          JET_PCSTR szFilename,
      __in_opt      JET_PCSTR szConnect,
      __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.

szConnect

Reserved for future use. Set to NULL.

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 JetCreateDatabase 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 JetSetSystemParameter).

JET_errDatabaseLocked

Indicates that another session has already opened the database exclusively (using JET_bitDbExclusive).

JET_errDatabaseNotFound

The database was not previously attached (See JetAttachDatabase).

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 Database Parameters.

JET_errOutOfMemory

The operation failed because memory could not be allocated.

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 JetCreateDatabase 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.

JetCreateDatabase will implicitly open the database. It is not necessarily 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 JetCreateDatabaseW (Unicode) and JetCreateDatabaseA (ANSI).

See Also

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