NAS & Session Killing

Dear All,

I want to install NAS on one of my Client PC (OS: Windows XP) to Kill the Ideal Session (Ideal Time: More than 1 One hour).

I have defined the 1 minute time Interval for the Navision Timer Automation (‘Navision Timer 1.0’.Timer) to execute code for killing Ideal session.

Will this setup create any issue in future ??

Kindly reply

Hi,

For killing the ideal session u can use following sql script

http://www.mibuso.com/dlinfo.asp?FileID=367

Regards

Amol

Thanks for reply.

But Our Database Sever is Native.

Hi Subrata,

You will need to give more background

Why a PC and not a server?

Are you using the Job Queue or your own (single instance?) codeunit?

Thanks Dave

PC will be an issue ?

I’m using single instance codeunit.

Hi Subrata,

Not directly, once you have it working, but PCs can be shutdown and then your code will not run. There shouldn’t be a big overhead on the server running this once every minute (depending on the code).

PC is always remain ON. My Code is given in Screen shot.

1616.nas.JPG

2746.nas.JPG

Dear DaveT,

I’m waiting for your reply.

Hi Subrata,

On what? Do you have a specific question or is the code not working?

Two issues I see:

  1. SLEEP is not needed

  2. No COMMIT

Thanks for reply.

SLEEP not required… Ok Fine.

Where to put COMMIT Function ? Why does it require ? Kindly reply.

8176.NAS Session killing Code.JPG

Hi Subrata,

Without testing it, I would not be sure that the DELETE command will commit the changes on exit of the NavisionTimer trigger so a COMMIT at the end would ensure this (you can of course test this). Have you tested this by manually runnig the object?

My Code is working fine though I have added COMMIT function at the end of Code ( Aa shown in previous Screen Shot).

Thank you again [Y]

Glad to Help [:D]

Subrata, the alignment, the indentation in your code, is all over the place. In a small trigger like this it doesn’t make much of a difference, but if you don’t force yourself to ALWAYS take good care of code indentation and alignment, your code will be very difficult to maintain. I know this from personal experience, where code that I had written years ago had very bad indentation (because I had tried to fit it into someone else’s modification) and when I needed to make a small change the code was almost impossible to read.

Teach yourself to ALWAYS use proper alignment, you will thank yourself for it later.

Dear Sir,

Thanks for your valuable suggestion…[Y]

Please provide a Well alignment & indentation CODE (Just an Example).

Thanks you.

No need for me to write your code for you. There is plenty of sample material for you to look at in a standard W1 database.

My code is working fine.[:D]

I’m not asking to write code for me.

I want to see indentation.

My indentation is not wrong.

Just because your code is working does not mean it’s written properly, and YES your indentation is indeed wrong. Your indentation is all over the place, with one character indentation in one line, then you have a space by an operator, then you don’t, then you have huge indentation by an AND statement, and then you indent wrong after that as well. Your indentation should consistently be two characters, and you should take care that ALL of your code is indented the same. This code might work, but it looks like crap. If this were more than a page of code, it would be very difficult to read. It is NOT indented correctly.

What you forgot there is that I’ve taken some time out of my very busy day to look at your work and give you some advice, because I thought you are a serious person that wants to do well. Instead of seriously looking at your work, you dismiss the advice and tell me that there’s nothing wrong with your code. This is the problem when you don’t learn how to do it the right way when you start out. Now you have a couple of years of experience and you’re not open to criticism. Your unwillingness to look at your own work is borderline arrogance, and if I were your senior we’d have a very serious talk about that attitude.

You posted a screenshot, and in order for me to show you how to indent, I would have to type all of your code, and I just don’t want to spend that much time on that. If you are seriously willing to listen you can post the actual code and I’ll show you how to indent it properly.

It’s up to you. If you want to be a better developer, you will seriously look at this. If you don’t then I will know that giving you any advice is a waste of my time.

I’m very much serious about the code and well indentation. I’m sorry if anything hurts you. My code is given below.

OnRun()
IF ISCLEAR(NavisionTimer) THEN
CREATE(NavisionTimer);
NavisionTimer.Interval := 60000;
NavisionTimer.Enabled := TRUE;

NavisionTimer::Timer(Milliseconds : Integer)
SELECTLATESTVERSION;
IF IdleSession.FINDSET THEN
REPEAT
IF (IdleSession.“User ID”<>‘SA’) AND (IdleSession.“Idle Time” >60000*60) AND
(IdleSession.“My Session”<>TRUE) THEN
IdleSession.DELETE;
UNTIL IdleSession.NEXT =0;
COMMIT;

Ah so you DID change the indentation. Here’s your original code:

8176.NAS Session killing Code.JPG

  • the REPEAT and UNTIL are indented just one space
  • Consequently, the IF statement is indented one space too little, only you don’t see it because of the indentation in the REPEAT
  • Both of those were changed in the code you pasted, so I’m happy to see that you did see that the indentation was not right after all.
  • In the IF statement, you have no spaces in one expression, and one space in another expression. It doesn’t really matter to me what you do, but make up your mind and be consistent. I always put spaces between operators, it makes it easier for me to read, and it’s also standard practice in C/AL programming
  • Either put all AND expressions on one line, or align them right underneath eachother.
  • I would put the THEN part on a new line, aligned the same as the IF part, so that the code that executes stands away from the IF statement
  • I also always put BEGIN and END in there, not always necessary, but it makes it easier to read for me and certainly easier to maintain

So this is what I would end up with:

NavisionTimer::Timer(Milliseconds : Integer)
SELECTLATESTVERSION;
IF IdleSession.FINDSET(TRUE,TRUE) THEN BEGIN
REPEAT
IF (IdleSession.“User ID” <> ‘SA’) AND
(IdleSession.“Idle Time” > 3600000) AND
(IdleSession.“My Session” <> TRUE)
THEN BEGIN
IdleSession.DELETE;
END;
UNTIL IdleSession.NEXT = 0;
COMMIT;
END;

  • Note that everything is consistently indented two characters, and all operators are surrounded by spaces. This makes it easier to visually scan the code and understand the structure
  • See how putting the THEN on its own line gives you a really quick visual clue where the conditions start and end. It’s not necessary, but it makes it easier to read
  • Don’t put a calculation in there if you don’t really need it. Instead of 60000 * 60, I changed it to the calculated value.
  • Get your FINDSET parameters right. You are deleting records, so they both need to be TRUE. Teach yourself to always specifically provide those parameters, and you force yourself to always think about them. Instead of just typing FINDSET, type FINDSET(FALSE,FALSE). It takes a second longer, but it forces you to actually think about it

In a small trigger like this it doesn’t make much of a difference, but when you’re trying to figure out pages of code, it makes a big difference if you don’t have to figure out the indentation first.

By the way, you can get the same result by filtering those fields and do DELETEALL:

NavisionTimer::Timer(Milliseconds : Integer)
SELECTLATESTVERSION;
IdleSession.SETFILTER(“User ID”,’<>SA’);
IdleSession.SETFILTER(“Idle Time”,’>3600000’);
IdleSession.SETRANGE(“My Session”,FALSE);
IdleSession.DELETEALL;
COMMIT;