StartBGSession(Int32,DBString,DBString,Int32) Method
- Last UpdatedNov 06, 2025
- 2 minute read
'Declaration
Public Overloads Shared Sub StartBGSession( _
ByVal clientType As Integer, _
ByVal clientAddress As DBString, _
ByVal reqdEvents As DBString, _
ByRef bgSessionId As Integer _
)
public static void StartBGSession(
int clientType,
DBString clientAddress,
DBString reqdEvents,
out int bgSessionId
)
Parameters
- clientType
- Required. Holds the client type.
- clientAddress
- Optional. Holds the client’s callback address for event notifications from the Middleware.
- reqdEvents
- Optional. Holds an XML-encoded string specifying for which events the client wishes to receive event notifications from the Middleware. Not implemented.
- bgSessionId
- Output. Holds the returned ID of the session that was started.
If the client type is “Background service,” then this method will first call the KillStaleSessions() method before attempting to create the new session. This will take care of the case of the computer that is running the background service being switched off instead of doing a normal shutdown, which would bypass the termination code that would have ended the session normally and so free up the license for the background service.
If successful, the method inserts an entry into the Sessn table and generates a unique session_id that is used to track this session in the future. The client needs to store this session ID for future calls.
An appropriate error description is returned if no further licenses of this client_type are available. The background service will log entries into the event log to allow the user to track down these errors.
The user_id field in the Sessn table for this new row is automatically populated from the system attribute user_id for background tasks, which avoids the need for a user to log on to these sessions. This allows audit trails to operate as normal with transactions initiated by these background applications. The client_address and reqd_events fields are for future implementation only, and are currently saved to the database but ignored thereafter.