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

JetBeginSession Function

· 52CE 我爱测

Learn more about: JetBeginSession Function

Applies to: Windows | Windows Server

JetBeginSession Function

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
    );

Parameters

instance

The database instance to use for this call.

psesid

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

szUserName

This parameter is reserved.

szPassword

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 Description
JET_errSuccess The operation completed successfully.
JET_errClientRequestToStopJetService 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 <a href="gg269240(v=exchg.10).md">JetStopService</a>.
JET_errInstanceUnavailable 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.
JET_errInvalidParameter 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.
JET_errNotInitialized It is not possible to complete the operation because the instance associated with the session has not been initialized yet.
JET_errOutOfMemory The operation failed because memory could not be allocated.
JET_errOutOfSessions The number of sessions the engine will allow the client to start is limited. This value can be changed using <a href="gg294044(v=exchg.10).md">JetSetSystemParameter</a> with the JET_paramMaxSessions constant. The default number of sessions is 16. See <a href="gg294139(v=exchg.10).md">System Parameters</a> for details about JET_paramMaxSessions.
JET_errRestoreInProgress It is not possible to complete the operation because a restore operation is in progress on the instance associated with the session.
JET_errTermInProgress 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.

Remarks

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.

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 JetBeginSessionW (Unicode) and JetBeginSessionA (ANSI).
See Also

JET_ERR
JET_INSTANCE
JET_SESID
JetBeginTransaction
JetCommitTransaction
JetDupSession
JetEndSession
JetResetSessionContext
JetRollback
JetSetSessionContext
JetStopService
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)

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

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