How to limit Navision login session (Nav 4 SP3)

nasheernasheer Member Posts: 78
edited 2008-06-13 in NAV Tips & Tricks
Hi,

I would like to know, how to limit user login connections to the server? (Using NAV 4 SP3)
If the user login sessions to the Database exceeds 3, how to close/logout programatically the last (4 th) user session.

I tried the below code in the Codeunit1 - 'LogInStart'

tblSession.RESET;
tblSession.SETRANGE("My Session",TRUE);
IF tblSession.FIND('-') THEN
BEGIN
fldUserLimit := 0;
tblDBUserLimit.RESET;
tblDBUserLimit.SETRANGE("Database Name",tblSession."Database Name");
IF tblDBUserLimit.FIND('-') THEN
fldUserLimit := tblDBUserLimit."No. Users Login";

tblSession1.RESET;
tblSession1.SETRANGE("Database Name",tblSession."Database Name");
IF tblSession1.FIND('-') THEN
NoOfLogins := tblSession1.COUNT;
END;

IF NoOfLogins > fldUserLimit THEN BEGIN
LogInEnd;

MESSAGE('You have no permission to login as all sessions are being used.');
CREATE(WSHell);
WSHell.SendKeys('%{F4}');
CLEAR(WSHell);
END;

My coding not working. The message prompts correctly, but still goes in.
Any one can help me.

Regards
Nasheer.

Answers

  • sendohsendoh Member Posts: 207
    instead of using
    MESSAGE('You have no permission to login as all sessions are being used.');

    try this.
    ERROR('You have no permission to login as all sessions are being used.');

    I didn't Test that hope will work..
    Sendoh
    be smart before being a clever.
  • nasheernasheer Member Posts: 78
    Hi Sendoh

    I tried using ERROR command as you mentioned. But still the same.
  • WaldoWaldo Member Posts: 3,412
    this is a known problem in codeunit 1.

    try first to put your message, then add ERROR('') after it. Like this:
    MESSAGE('You have no permission to login as all sessions are being used.'); 
    ERROR('');
    

    I was struggling with this myself in the past (here).

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • nasheernasheer Member Posts: 78
    Hi Waldo

    Thanks for your message. If i remove the message and error commands, the code works. But how to display the warning message?

    Regards
  • WaldoWaldo Member Posts: 3,412
    Didn't say you have to remove it :| .

    What I meant was, try to use this code (I only added one line)
    tblSession.RESET; 
    tblSession.SETRANGE("My Session",TRUE); 
    IF tblSession.FIND('-') THEN 
    BEGIN 
    fldUserLimit := 0; 
    tblDBUserLimit.RESET; 
    tblDBUserLimit.SETRANGE("Database Name",tblSession."Database Name"); 
    IF tblDBUserLimit.FIND('-') THEN 
    fldUserLimit := tblDBUserLimit."No. Users Login"; 
    
    tblSession1.RESET; 
    tblSession1.SETRANGE("Database Name",tblSession."Database Name"); 
    IF tblSession1.FIND('-') THEN 
    NoOfLogins := tblSession1.COUNT; 
    END; 
    
    IF NoOfLogins > fldUserLimit THEN BEGIN 
    LogInEnd; 
    
    MESSAGE('You have no permission to login as all sessions are being used.');
    ERROR('');    //**** ONLY THIS WAS ADDED TO YOUR CODE
    CREATE(WSHell); 
    WSHell.SendKeys('%{F4}'); 
    CLEAR(WSHell); 
    END;
    

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • nasheernasheer Member Posts: 78
    Hi Waldo

    Thank you very much for your support. I tried as you mentioned, but still not working. And if I remove the message, it works, not allow to login (close the Navision Client).

    Regards
  • WaldoWaldo Member Posts: 3,412
    Hm,
    I decided just to test your code, and you were right. Strange behaviour in CU1, isn't it ... :(. Allthough I remember that we built a similar functionality in a 3.7 database. Never had problems with it (just with an ERROR statement).

    Well, I just see a few (definitely not nice) solutions. You want to show the message, and to close your client afterwards. The ERROR doesn't work, and the MESSAGE is not useful (is always shown at the end of the process).

    So, the only things you have (from the op of my head) is:
    - a dialog
    - a CONFIRM
    - a custom form

    Using a dialog could be something like:
      dlgDialog.OPEN('You have no permission to login as all sessions are being used.');
      SLEEP(1000);
      dlgDialog.CLOSE;
      CREATE(WSHell);
      WSHell.SendKeys('%{F4}');
      CLEAR(WSHell);
    

    Using a CONFIRM gives you the advantage that the user must push a button to close it - and has read whatever was going on:
      IF CONFIRM('You have no permission to login as all sessions are being used.') THEN;
      CREATE(WSHell);
      WSHell.SendKeys('%{F4}');
      CLEAR(WSHell);
    
    Also not really nice, because of the fact that you get "yes/No" buttons, which don't make sense... .

    For the custom form, you can build your own form with that OK-button, and the message in a caption or whatever. You code would look something like:
      FORM.RUNMODAL(FORM::"My Error Message Form");
      CREATE(WSHell);
      WSHell.SendKeys('%{F4}');
      CLEAR(WSHell);
    

    These are just a few suggestions. I'm sure there are better ones.

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • kinekine Member Posts: 12,562
    You can use the Popup function of the WSH to show some dialog when closing the company... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • nasheernasheer Member Posts: 78
    Hi Waldo And Kine.

    Thanks for your support. I tried Waldo's suggesstions first.
    Using CONFIRM command, still the user able to login.
    And tried using Dialog, it works.

    I prefered Kine's suggesstion to use WSH Popup, it works fine.

    Thank you once again for your help to solve the problem.

    Best Regards
  • WaldoWaldo Member Posts: 3,412
    The confirm worked with me as well .. but anyway.

    I tested the Popup and it works perfectly. Definitely the best solution. For the people who care:
    CREATE(WSHell);
    //To Show the error message
    WSHell.Popup('You have no permission to login as all sessions are being used.'); 
    //To close the client
    WSHell.SendKeys('%{F4}'); 
    CLEAR(WSHell);
    

    =D>

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • kinekine Member Posts: 12,562
    Waldo wrote:
    The confirm worked with me as well .. but anyway.

    I tested the Popup and it works perfectly. Definitely the best solution. For the people who care:
    CREATE(WSHell);
    //To Show the error message
    WSHell.Popup('You have no permission to login as all sessions are being used.'); 
    //To close the client
    WSHell.SendKeys('%{F4}'); 
    CLEAR(WSHell);
    

    =D>

    And you can add two more parameters to set the title of the dialog to something meaningful... 8) (but you need to use two variables...)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • WaldoWaldo Member Posts: 3,412
    I didn't now the WShell Popup, so I learned something new today. \:D/
    Thanks, Kine.

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • kinekine Member Posts: 12,562
    Every day you can find something to learn... :-D and mainly on MiBuSo... 8)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • WaldoWaldo Member Posts: 3,412
    True. But I don't have too much time any more. Only now, when i'm sick :)

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • krikikriki Member, Moderator Posts: 9,094
    Another way to limit the user sessions is this : http://www.mibuso.com/howtoinfo.asp?FileID=18

    [Topic moved from Navision forum to Navision Tips & Tricks forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.