To save concurrent uses in NAV it might be a good idea to kill idle connections automatically.
This can be done by looping through the Session Virtual Table and check the Idle Time field. I like to add the field “Maximum Idle Time” to the User Setup table and compare that field to the Idle Time in the Session table before deciding to kill the session.
The use running this batch must have permission to kill sessions on the SQL Server.
[code htmlscript=”false”]IF ISCLEAR(ADOConnection) THEN
IF NOT CREATE(ADOConnection) THEN
ERROR(Text001);
IF ADOConnection.State = 1 THEN
ADOConnection.Close;
ADOConnection.Open(
‘Driver={SQL Server Native Client 10.0};’ +
‘Server=<ServerName>;’ +
‘Database=<DatabaseName>;’ +
‘Trusted_Connection=yes;’);
ADOConnection.CommandTimeout(0);
Session – OnAfterGetRecord()
IF "Application Name" <>
‘Microsoft Dynamics NAV Classic client’
THEN
CurrReport.SKIP;
BackSlashPos := STRPOS("User ID",’\’);
IF NOT
UserSetup.GET(
UPPERCASE(COPYSTR("User ID",BackSlashPos + 1)))
THEN
CurrReport.SKIP;
IF FORMAT(UserSetup."Maximum Idle Time") = ” THEN
CurrReport.SKIP;
Idle := "Idle Time";
MaxIdle := (UserSetup."Maximum Idle Time" – 000000T);
IF Idle < MaxIdle THEN
CurrReport.SKIP;
ADOConnection.Execute(STRSUBSTNO(‘KILL %1’,"Connection ID"));
Session – OnPostDataItem()
ADOConnection.Close;
CLEAR(ADOConnection);[/code]
Name | DataType | Subtype | Length |
UserSetup | Record | User Setup | |
ADOConnection | Automation | ‘Microsoft ActiveX Data Objects 2.8 Library’.Connection | |
MaxIdle | Decimal | ||
Idle | Decimal | ||
BackSlashPos | Integer |
This can be added as a Job Queue Batch.
See here to check for required permission to use the kill statement.