{"title":"Session.StopSession(Integer [, Text]) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/session/session-stopsession-method/","by":"JOP-AL","license":"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.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/session/session-stopsession-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Stops a session.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"Session.StopSession(Integer [, Text]) Method","slug":"sessionstopsessioninteger-text-method","at":0,"chars":2202},{"level":2,"title":"Syntax","slug":"syntax","at":124,"chars":163},{"level":2,"title":"Parameters","slug":"parameters","at":287,"chars":462},{"level":2,"title":"Return Value","slug":"return-value","at":749,"chars":238},{"level":2,"title":"Remarks","slug":"remarks","at":987,"chars":730},{"level":2,"title":"Example","slug":"example","at":1717,"chars":350},{"level":2,"title":"Related information","slug":"related-information","at":2067,"chars":135}],"text":"# Session.StopSession(Integer [, Text]) Method\n> Version: _Available or changed with runtime version 1.0._\nStops a session.\n## Syntax\n```al\n[Ok := ]  Session.StopSession(SessionId: Integer [, Comment: Text])\n```\n> NOTE\n> This method can be invoked without specifying the data type name.\n## Parameters\nSessionId\nType: ../integer/integer-data-type\nThe ID of the session that you want to stop.The session can be any of the following:\n Windows client session\n Web client session\n NAS services session\n SOAP web services client session\n OData web services client session\n Background session\n*[Optional] Comment*\nType: ../text/text-data-type\nAn optional comment about the session event. The comment is stored in Table 2000000111, the Session Event table.\n## Return Value\n*[Optional] Ok*\nType: ../boolean/boolean-data-type\ntrue 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.\n## Remarks\nThe 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.\n> NOTE\n> If the current executing statement is the Sleep method, then the session is stopped immediately.\nWhen 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.\nYou cannot stop the current, active session in which you are executing the StopSession call.\n## Example\nThis example assumes that you have a table named CacheStressTest that you use for testing.\n```al\nvar\n    CacheStressTestRec: Record Customer;\n    SessionID: Integer;\nbegin\n    StartSession(SessionId, CodeUnit::\"Cache Stress Test\", CompanyName, CacheStressTestRec);\n    StopSession(SessionId, 'Logoff cache stress test session');\nend;\n\n```\n## Related information\nsession-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}