Windows Dev Center

Collapse the table of content
Expand the table of content
Expand Minimize

JetBeginSession Function


Last modified: January 09, 2012

Applies to: Windows | Windows Server

The JetBeginSession function starts a session and initializes and returns an ESE session handle (JET_SESID). Sessions control all access to the database and are used to control the scope of transactions. The session can be used to begin, commit, or abort transactions. The session is also used to attach, create, or open a database. The session is used as the context for all DDL and DML operations. To increase concurrency and parallel access to the database, multiple sessions can be begun.

JET_ERR JET_API JetBeginSession(
  __in          JET_INSTANCE instance,
  __out         JET_SESID* psesid,
  __in_opt      JET_PCSTR szUserName,
  __in_opt      JET_PCSTR szPassword



The database instance to use for this call.


Pointer to the variable that the session handle initializes on successful return.


This parameter is reserved.


This parameter is reserved.

Return Value

This function allows for the return of any JET_ERRs that are defined in this API. For more information about Jet errors, see Extensible Storage Engine Errors and Error Handling Parameters.

Return code



The operation completed successfully.


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.


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.


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.


It is not possible to complete the operation because the instance associated with the session has not been initialized yet.


The operation failed because memory could not be allocated.


The number of sessions the engine will allow the client to start is limited. This value can be changed using JetSetSystemParameter with the JET_paramMaxSessions constant. The default number of sessions is 16. See System Parameters for details about JET_paramMaxSessions.


It is not possible to complete the operation because a restore operation is in progress on the instance associated with the session.


It is not possible to complete the operation because the instance associated with the session is being shut down.

On success, the session handle is initialized, and may be used for database operations.

On failure, there are no available sessions or a new session was unable to be initialized.


Careful attention must be used when using sessions across different threads. A session tracks which thread it was used on during JetBeginTransaction, JetCommitTransaction, or JetRollback, and it will throw an error if used on multiple threads with an open transaction. The JetResetSessionContext, JetSetSessionContext can change this behavior. Since the session is still a serialized context, and multiple database operations cannot be performed on a single session concurrently, only serially. However, you can use multiple sessions to achieve concurrent database access. Sessions can be used inside a transaction across threads by setting and resetting the session contexts.

The session handle should be closed with JetEndSession.



Requires Windows Vista, Windows XP, or Windows 2000 Professional.


Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server.


Declared in Esent.h.


Use ESENT.lib.


Requires ESENT.dll.


Implemented as JetBeginSessionW (Unicode) and JetBeginSessionA (ANSI).

See Also

© 2015 Microsoft