How to select the RTC client session with the biggest idle time to kill with STOPSESSION?

gycsiakgycsiak Posts: 7Member
edited 2019-03-20 in NAV Three Tier
Hi there,

Does anyone know how to query from Dynamics NAV code the system tables or session tables to get to know, which session is idle for the longest time and so to kill it via STOPSESSION, but to leave out Users with a custom boolean flag like "Protected", so that nevertheless, one of these users are idle for the longest period, but my code wouldn't run STOPSESSION on these users' session.

Thanks anyway, but I would like to do this from NAV NAS, not from SQL directly, if possible, searched and googled it for a long time, so now I think I ask the forum, thank you in advance!

Best regards,

Gyula

Answers

  • gycsiakgycsiak Posts: 7Member
    edited 2019-03-20
    This is, what I found from SQL side and have modified the original script, so that the session record with sleeping status and the biggest difference between login_time and last_batch, but I would like to make it much more elegant, than this:

    SELECT top 1 *
    FROM master..sysprocesses (NOLOCK)
    WHERE spid>50
    AND loginame <> 'DIR%'
    AND status='sleeping'
    and [program_name] = 'Microsoft Dynamics NAV Server'
    order by DATEDIFF(mi,last_batch,login_time) asc

    UPDATE:
    Sadly, from SQL I can only query the service connections, but not the client connections running through the service.
  • Slawek_GuzekSlawek_Guzek Posts: 1,649Member
    You can look into Active Session table, there is the "Login Datetime" field in there, you can use it to find and kill the oldest sessions, but apart from that I don't think you'd be able to retrieve the session's 'idle' time and find the oldest inactive sessions.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • gycsiakgycsiak Posts: 7Member
    edited 2019-03-20
    Yes, thanks, I found it as well, the idle session time was the question in my case. I could only query it from master sysobjects, but not from standard NAV system tables, but sadly, from SQL I can only query the service connections, but not the client connections running through the service.
  • Developer101Developer101 Posts: 295Member
    edited 2019-03-14
    wrong post
    United Kingdom
  • gycsiakgycsiak Posts: 7Member
    wrong post

    Why wrong?
  • Developer101Developer101 Posts: 295Member
    sorry i was typing my reply which was meant for another post and i could not delete it so i edited it to wrong post.. just ignore it :)
    United Kingdom
Sign In or Register to comment.