Ending an idle session
Idle users utilize sessions in the system and also leave the application available to people who should not be using it. This recipe will show you how to create a small program to end these sessions.
How to do it...
Create a new codeunit from Object Designer.
Add the following global variable:
Name
Type
Subtype
Session
Record
Session
Add the following code to the
OnRun
trigger:Session.SETFILTER("Idle Time", '>%1', 1800000); Session.DELETEALL;
Save and close the codeunit.
How it works...
The session table contains a field called Idle Time. This field is a Duration data type which is similar to an integer. The value in the field represents the number of milliseconds that have elapsed since the user was active. In our example, we use the number 1,800,000 which is equal to 30 minutes. If we find any sessions that have been idle for longer than that, we delete them from the Session table which kills their connection to the database.
There's more...
This code is obviously...