Kill Session using Codeunit

AngeloAngelo Member Posts: 180
Hello Master,

is it possible to make function for killing session without using Store Procedure(ADO)? That's mean just using C/AL code.Anybody can share,please?

Regards,
Angelo

Comments

  • klavinklavin Member Posts: 117
    Searching the forum for "session kill" can get some good results, see the How to:
    http://www.mibuso.com/howtoinfo.asp?FileID=18

    or article below...

    viewtopic.php?t=26024&highlight=session+kill

    -Lavin
    -Lavin
    "Profanity is the one language all programmers know best."
  • AngeloAngelo Member Posts: 180
    Ok,Thanks klavin...

    I got the clue now...

    My next question, How to setfilter "duration" datatype? as we know that duration has value for day,hour,minutes,second.
    for e.g 1 day 5 hours 40 minutes 8 seconds. How to filter idle time in session table for more than 2 hours ?

    session.setfilter("idle time", ???);
  • AngeloAngelo Member Posts: 180
    please forget my last question.... :lol:

    I've already got the answer... \:D/


    Thanks....
  • strykstryk Member Posts: 645
    With SQL Server you could also kill idle session with some TSQL:
    use [master]
    go
    set statistics io off
    set nocount on
    go
    declare @threshold datetime
    set @threshold = dateadd(hour, -6, getdate())  -- threshold is 6 hours ago
    print 'Killing processes which executed "Last Batch" before ' + convert(varchar(30), @threshold, 113)
    print ''
    declare @spid int, @last_batch datetime
    declare spid_cur cursor for
      select [spid], [last_batch] from sysprocesses
      where [program_name] = 'Microsoft Business Solutions-Navision client'  -- change application name here
        and [last_batch] <= @threshold
    open spid_cur    
    fetch next from spid_cur into @spid, @last_batch
    while @@fetch_status = 0 begin
      print 'Killing process ' + convert(varchar(5), @spid) + ', idle since ' + convert(varchar(30), @last_batch, 113)
      exec ('kill ' + @spid)
      fetch next from spid_cur into @spid, @last_batch
    end
    close spid_cur    
    deallocate spid_cur    
    go
    
    This script searches for NAV processes which have executed the last batch 6 hours ago (please change the settings if applicable) and kills them. YOu could create a SQL Agent job which execute this script every hours.
    If necessary you have to add some exception handling etc..

    USE AT OWN RISK!
    Jörg A. Stryk (MVP - Dynamics NAV)
    NAV/SQL Performance Optimization & Troubleshooting
    STRYK System Improvement
    The Blog - The Book - The Tool
Sign In or Register to comment.