PowerShell commands to kill active sessions

rsaritzky
Member Posts: 469
Hi all,
I'm trying to create a PowerShell script to kill some active sessions when there are too many users logged in - some of them log in multiple times (yes, we are trying to train them not to) and I cannot log in myself to kill sessions from within NAV. We have 3 service tier machines, so using the GetSession powershell cmdlet doesn't help much. So I'm going down the path of running a sql query against the [Active Session] table to identify users who are logged in more than once.
My questions are:
1. Is there a way to tell from the [Active Session] table which SQL session is being used, so I could use a SQL KILL command?
2. Does anyone know if I run a DELETE FROM [Active Session] where [Session ID] = 'xxxx' will kill a user's session? Or any other SQL command to kill a user session?
Thanks
Ron
I'm trying to create a PowerShell script to kill some active sessions when there are too many users logged in - some of them log in multiple times (yes, we are trying to train them not to) and I cannot log in myself to kill sessions from within NAV. We have 3 service tier machines, so using the GetSession powershell cmdlet doesn't help much. So I'm going down the path of running a sql query against the [Active Session] table to identify users who are logged in more than once.
My questions are:
1. Is there a way to tell from the [Active Session] table which SQL session is being used, so I could use a SQL KILL command?
2. Does anyone know if I run a DELETE FROM [Active Session] where [Session ID] = 'xxxx' will kill a user's session? Or any other SQL command to kill a user session?
Thanks
Ron
Ron
1
Best Answer
-
We run into this issue and now limit users to 1 Active Session. We do this by subscribing to the event OnBeforeCompanyOpen in Codeunit 1. Which calls this function...
IF (SESSION.CURRENTEXECUTIONMODE = EXECUTIONMODE::Standard) AND (SESSION.CURRENTCLIENTTYPE = CLIENTTYPE::Windows) THEN BEGIN ActiveSession.SETRANGE("User ID",USERID); ActiveSession.SETRANGE("Client Type",ActiveSession."Client Type"::"Windows Client"); ActiveSession.SETFILTER("Session ID", '<>%1', SESSIONID); IF ActiveSession.FINDFIRST THEN IF CONFIRM(OpenNewSessionConf) THEN STOPSESSION(ActiveSession."Session ID") ELSE ERROR(TooManyOpenSessionsErr); END;
This has solved the issue for us, hope this helps.5
Answers
-
NAV uses connection pooling, so dont do anything in sql.
In newer versions, multiple clients from the same user shouldn’t eat up licenses.
Create a function in codeunit 1 and check on open company if user has client running, if windows, or check the sessiontable.Follow me on my blog juhl.blog0 -
Active Session table is just a regular table now. Deleting a record from it will not remove actual session.
There is no way to map NST sessions visible at the SQL server to actual users sessions - unless you set up one NST per one user, and each NST will run under different service accountSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
We run into this issue and now limit users to 1 Active Session. We do this by subscribing to the event OnBeforeCompanyOpen in Codeunit 1. Which calls this function...
IF (SESSION.CURRENTEXECUTIONMODE = EXECUTIONMODE::Standard) AND (SESSION.CURRENTCLIENTTYPE = CLIENTTYPE::Windows) THEN BEGIN ActiveSession.SETRANGE("User ID",USERID); ActiveSession.SETRANGE("Client Type",ActiveSession."Client Type"::"Windows Client"); ActiveSession.SETFILTER("Session ID", '<>%1', SESSIONID); IF ActiveSession.FINDFIRST THEN IF CONFIRM(OpenNewSessionConf) THEN STOPSESSION(ActiveSession."Session ID") ELSE ERROR(TooManyOpenSessionsErr); END;
This has solved the issue for us, hope this helps.5 -
Nick and Juhl,
Thanks for this suggestion - this is a perfect solutionRon0 -
Hi rsaritzky,
You can try achieving this by using the Idle Client Timeout feature in NAV.
So that system will automatically close / Kill the idle sessions after a specified interval of time.
Thanks0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions