How to control/kill sessions?

AdministratorAdministrator Member, Moderator, Administrator Posts: 2,499
edited 2014-09-22 in How Tos section
How to control/kill sessions?

http://www.mibuso.com/howtoinfo.asp?FileID=18

Discuss this How To here.
«13

Comments

  • rolflinrolflin Member Posts: 0
    I have some trouble using this.

    I've installed de NAS and the code, forms and tables. But it remains unusable:

    The definition of the field User ID was changed after the object was saved

    Old type: Text
    New type: Code

    Any idea?


    Best regards(I've searched over and no answer at all)
  • krikikriki Member, Moderator Posts: 9,110
    Did you try to recompile the objects?
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • rolflinrolflin Member Posts: 0
    I've tried to recompile.

    But no luck...Usding Native NAV(NOT SQL) i think the method FINDFIRST is not possible.



    I'm using nav 4.0 sp1.

    Any idea ?
  • krikikriki Member, Moderator Posts: 9,110
    I imported the objects on a 4.0SP1 native.
    First I had the same error as you. Then I recompiled and I got no more errors.

    2 things come in mind to test:
    1) maybe the codeunit was in memory and after compiling it remained there. If you re-open the client it should take the new version of the codeunit and the problem should be solved.
    2) If you have a problem with FINDFIRST, it means you have a client before 4.0SP1. FINDFIRST was introduced with 4.00SP1.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • rolflinrolflin Member Posts: 0
    You're right.

    We are planning to change the NAV partner, ours is %&%&**

    I'm learning to control, program and debug my system.

    I have a SUPER rol but i can't run some codeunits design some forms...
    Any idea? its the license? I cant design even having all access to tables, forms codeunits and so on?
  • rolflinrolflin Member Posts: 0
    Ok right i think our license doesnt have design granule
    So i can work on a local copy of the db.

    I hace setup up all the fobs on the dev nav and exported and imported on the porduction db.

    Tha NAS starts but the user need some perms that i cannot find.

    I have created arole sessionkiller with acces to te session table and all the objects in the fobs(tables, forms, and codeunit)

    But i still missing something
  • krikikriki Member, Moderator Posts: 9,110
    If you run the codeunit from your client, does it work then?
    If it works, than probably you still need to put the call to this codeunit in codeunit 1.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • vijay4398vijay4398 Member Posts: 35
    Does this solution works for Native Navision DB also? I tried to do this ...everything works ..but session is not killed.

    If this does not apply to native databases..do we have any other solution.


    Thanks in advance

    Vijay
  • garakgarak Member Posts: 3,263
    yes you can kill the session also in the native database (>= 4.00)
    For test: Open Database -> File -> Database -> Information -> Sessions -> active Sessions -> DrillDown -> SessionList -> F4 to kill a session
    Do you make it right, it works too!
  • vijay4398vijay4398 Member Posts: 35
    Thanks for the reply...but my query is regarding the auto session killing through code which we are talking in the posts above.

    Will this code work with Native DB as well?


    Thanks
    Vijay
  • krikikriki Member, Moderator Posts: 9,110
    vijay4398 wrote:
    Thanks for the reply...but my query is regarding the auto session killing through code which we are talking in the posts above.

    Will this code work with Native DB as well?


    Thanks
    Vijay
    Yes.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • rdebathrdebath Member Posts: 383
    rolflin wrote:
    The definition of the field User ID was changed after the object was saved

    Old type: Text
    New type: Code

    This is a common error. It's caused because the type of the "User ID" on the virtual table is different between Native and SQL. You have to SAVE the object (normally a form) again, not just recompile from the object designer.

    Second minor point, for the F4 kill to work on SQL the user must be a member of the SQL system administrator role with delete permission on the Navision session table. Just being a member of the Navision SUPER group is not enough.
  • tco35tco35 Member Posts: 0
    Great job ! Unfortunatelly I'm unable to launch CU because of a error "you can use FINDSET only if keys are acending ordered" (table session).

    IF PtmpSession.SETCURRENTKEY("Idle Time") THEN BEGIN
    // I am on SQL. SQL has a key on "Idle Time".
    PtmpSession.ASCENDING(FALSE);
    IF PtmpSession.FINDSET THEN <---- ERROR here

    I'm using Nav 4.03 with SQL Server 2005. I'm able to sort on idle time in session form so i think the key is present. So ?

    Tco
  • garakgarak Member Posts: 3,263
    The findset command was a part of SP1. And is not designed for desc. Order (PtmpSession.ASCENDING(FALSE);)
    So, change from findset to find('-').

    regards
    Do you make it right, it works too!
  • tco35tco35 Member Posts: 0
    possible bug ? : in FindSessionToDelete you search for DOMAIN\USERID in tmpSessionKillerMaxUserSess table witch contains user ID "modified" by GetUserID (without domain name)

    IF ItmpSessionKillerMaxUserSess.GET(PtmpSession."User ID") THEN
    IF NOT ItmpSessionKillerMaxUserSess."Never Kill Session" THEN
    EXIT(TRUE);

    Modified like this and it works for me :
    //IF ItmpSessionKillerMaxUserSess.GET(PtmpSession."User ID") THEN
    tmpICodeUserID := GetUserID(PtmpSession);
    IF ItmpSessionKillerMaxUserSess.GET(tmpICodeUserID) THEN
    IF NOT ItmpSessionKillerMaxUserSess."Never Kill Session" THEN
    EXIT(TRUE);

    Regards,

    Tco
  • flip69flip69 Member Posts: 0
    I do have the CU 8000 running and the Dashboard Form shows the sessions are checked every N seconds.

    My problem is that no sessions are shown in the sessions table and no sessions are killed. Do I need to define the database or company somewhere in the CU?

    I'm using NAV 6 with SQL Server and just run the CU out of the client for testing.

    Phil
  • krikikriki Member, Moderator Posts: 9,110
    It is possible your sessions are all very active. Only sessions that are inactive longer than the optionally kill period are shown.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • spiky_goldenspiky_golden Member Posts: 44
    I don't know if you still can help me but I'm having trouble with the code unit. I Manage to change the codeunit (FINDSET vs FINDFIRST). I can see all the sessions that are inactive for more than 2 minutes. But no session get kill. I set OptionKill at 1 minutes and the Always Kill at 3 minutes (testing purpose). I can see my test sessions stay there as long as I don't close manually the application. (No user have the "never kill" option)

    When I run the manually the code unit It run every x seconds as I ask him to do... but still no killing...

    Is there any specific privilege (DB right or roles) I should set on every sessions or only on the account that run the NAS?

    2010-08-20 12:51
    EDIT: The problem occured only on windows session. Session with SQL logins are killed
    Patrick Venner
    programmeur-analyste
    Cabico Custom Cabinetry
  • krikikriki Member, Moderator Posts: 9,110
    It shouldn't be a problem. If DB users are killed, also Windows users should be killed.
    Instead of using a NAS, open a client and run the codeunit using the debugger to see what is happening.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • spiky_goldenspiky_golden Member Posts: 44
    Thanks for the reply, I tried and can't figure out... So I decide to go an other way... A Job that runs on the sql server, it remove the load from the client and give me the possibility to log and do more stuff without taking out Navision object as they are limited in numbers (licence).
    Patrick Venner
    programmeur-analyste
    Cabico Custom Cabinetry
  • navuser1navuser1 Member Posts: 1,329
    How to control/kill sessions?

    http://www.mibuso.com/howtoinfo.asp?FileID=18

    Discuss this How To here.


    The form should be always open to kill the Idle session. Is it ???
    Now or Never
  • navuser1navuser1 Member Posts: 1,329
    I have seen that few C/AL code are written under the Ontimer trigger of the Form Session Killer Sessions (ID = 80002).
    Can someone explain How does CurrForm.update(false) work here ???
    Now or Never
  • krikikriki Member, Moderator Posts: 9,110
    Actuall, the form does not kill anything. it is a dashboard for doing some setup and showing the current sessions.

    It is the codeunit that has a license to kill. :)
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • navuser1navuser1 Member Posts: 1,329
    kriki wrote:
    Actuall, the form does not kill anything. it is a dashboard for doing some setup and showing the current sessions.

    It is the codeunit that has a license to kill. :)

    Ok. Thanks...
    The dashboard should always be kept open to kill the Idle Session. Is it ???

    I have seen in the debbuging mode that The Code under the OnTimer trigger of the Form (I have mentioned already) always Jump to the Codunit . How it is possible ??
    Now or Never
  • navuser1navuser1 Member Posts: 1,329
    Which Granual ID is for NAS in Dynamic Nav License ??? Kindly reply.
    Now or Never
  • krikikriki Member, Moderator Posts: 9,110
    You don't need to have the form open to kill sessions.
    The NAS using the codeunit kills the sessions.

    Each customer license has 1 NAS for free.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • navuser1navuser1 Member Posts: 1,329
    kriki wrote:
    You don't need to have the form open to kill sessions.
    The NAS using the codeunit kills the sessions.

    Each customer license has 1 NAS for free.

    You have said in another post that "Function with ID 99 in codeunit 1 is only lauched once at the start of the NAS. It launches the code in that function and then finishes, never to enter again in that function."
    Now or Never
  • navuser1navuser1 Member Posts: 1,329
    kriki wrote:
    You don't need to have the form open to kill sessions.
    The NAS using the codeunit kills the sessions.

    Each customer license has 1 NAS for free.

    How will NAS kill the Idle Session ??

    Will NAS call the Session Killer Codeunit again again automatically . ??
    Now or Never
  • karthikeyan_atnakarthikeyan_atna Member Posts: 0
    I have written a small code for killing a Session in NAV 2009 SP1 but i dont know that it's properly working or not.. As i'm new to NAV PLS help me...OR give me a sample code....

    CODE:

    MaxUserIdleTime is the maximum idle time for a user after which his session should be deleted.
    tempIdleTime is a variable where maximum user idle time will be getting updated.


    MaxUserIdleTime := 10000;
    tempIdleTime := 0;
    recSession.SETRANGE(recSession."Database Name",'Demo Database NAV (6-0)_Old');
    License := recSession.COUNT;
    IF License > 2 THEN
    BEGIN
    IF recSession.FINDFIRST = TRUE THEN
    BEGIN
    REPEAT
    BEGIN
    IF recSession."Idle Time" >= MaxUserIdleTime THEN
    BEGIN
    IF recSession."Idle Time" >= tempIdleTime THEN
    BEGIN
    tempIdleTime := recSession."Idle Time";
    SesId := recSession."Connection ID";
    END;
    END;
    END;
    UNTIL recSession.NEXT = 0;
    END;
    END;
    MESSAGE('%1',tempIdleTime);
    MESSAGE('%1',SesId);
    //recSession.SETRANGE(recSession."Connection ID",SesId);
    IF License > 2 THEN
    BEGIN
    IF recSession.FINDFIRST = TRUE THEN
    REPEAT
    BEGIN
    IF recSession."Idle Time" >= tempIdleTime THEN
    BEGIN
    recSession.DELETE(TRUE);
    MESSAGE('deleted');
    COMMIT;
    EXIT;
    END;
    END;
    UNTIL recSession.NEXT = 0;
    END;
  • adiraneadirane Member Posts: 5
    I'm trying to import this objects, I'm using Microsoft Dynamics NAV 2009 SP1, and my error is the following:
    "Automation is not an option. The existing options are: System, File, TransactionType", this occurs when Dynamics is importing this line (Object Codeunit 80000 Session Killer):

    autNavisionTimer@1101322000 : Automation "{3B311C81-140E-11D5-8B18-00D0590B4EC5} 1.0:{3B311C92-140E-11D5-8B18-00D0590B4EC5}:'Navision Timer 1.0'.Timer" WITHEVENTS;

    Thanks.
Sign In or Register to comment.