Options

PowerShell commands to kill active sessions

rsaritzkyrsaritzky 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
Ron

Best Answer

Answers

  • Options
    JuhlJuhl Member Posts: 724
    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.blog
  • Options
    Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    edited 2017-10-23
    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 account
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • Options
    rsaritzkyrsaritzky Member Posts: 469
    Nick and Juhl,

    Thanks for this suggestion - this is a perfect solution
    Ron
  • Options
    vivek4121vivek4121 Member Posts: 165
    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.

    Thanks
Sign In or Register to comment.