# Session.StopSession(Integer [, Text]) Method
> Version: _Available or changed with runtime version 1.0._
Stops a session.
## Syntax
```al
[Ok := ]  Session.StopSession(SessionId: Integer [, Comment: Text])
```
> NOTE
> This method can be invoked without specifying the data type name.
## Parameters
SessionId
Type: ../integer/integer-data-type
The ID of the session that you want to stop.The session can be any of the following:
 Windows client session
 Web client session
 NAS services session
 SOAP web services client session
 OData web services client session
 Background session
*[Optional] Comment*
Type: ../text/text-data-type
An optional comment about the session event. The comment is stored in Table 2000000111, the Session Event table.
## Return Value
*[Optional] Ok*
Type: ../boolean/boolean-data-type
true if the operation was successful; otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.
## Remarks
The session that you want to stop and the session that calls StopSession must be running on the same instance of Dynamics 365 Business Central service. The session is stopped before the next AL statement executes. Open transactions are rolled back.
> NOTE
> If the current executing statement is the Sleep method, then the session is stopped immediately.
When a session is executing AL that does not interact with the server connection or the access lock used by the connection, StopSession cannot terminate the connection. StopSession can terminate connections that are inactive, idle, or using the database but not blocked.
You cannot stop the current, active session in which you are executing the StopSession call.
## Example
This example assumes that you have a table named CacheStressTest that you use for testing.
```al
var
    CacheStressTestRec: Record Customer;
    SessionID: Integer;
begin
    StartSession(SessionId, CodeUnit::"Cache Stress Test", CompanyName, CacheStressTestRec);
    StopSession(SessionId, 'Logoff cache stress test session');
end;

```
## Related information
session-data-type
Get Started with AL<../../devenv-get-started>
Developing Extensions<../../devenv-dev-overview>

Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/session/session-stopsession-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact. https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/session/session-stopsession-method/
