How tos

How To install a NAV Application Server (NAS)?

Author
Alain Krikilion (alias kriki)
Website
http://mibuso.com/blogs/kriki
Date
28/01/2008
Size
26,56 KB
Downloads
4932
Rating
432150
Popularity
Downloaded 5 times in the last two weeks
A lot of people wonder what needs to be done to install and make work a NAS. In reality it is not so difficult. But if you need to read the manual, it sounds more complicated than it is. This because the manual describes in detail all options and possibilities. This manual describes ONLY the steps I generally take to install a NAS.
I already explained it some times to different colleagues how to do it. They take notes and when they need them, they can’t read them. ;-)
So I decided to create a small how-to to install a NAS.

1. Where to install it?

You can install it on the server or on any other PC. What is the best? Until some years ago it was better NOT to install it on the server because the NAS can use all processing power of the CPU leaving little for the database server. At the moment, this is not so much of a problem with most servers having multiple CPU’s or cores (I’ll be using CPU for now on, but it can also mean a core in a CPU). The NAS uses 1 core.

If you have a Navision-server, there should be no problem, because it uses only 1 core and not even that much. The only negative could be that both NAS and DB-server use the same core. I don’t know if it is possible to control that, but I hope that Windows tries to divide the load and puts them on different cores.

If you have a SQL-server, you definitely need multiple cores (I would say 4 cores is a minimum for SQL). Even if 1 core is fully occupied with the NAS, there are 3 cores free for SQL. In normal conditions, a Navision-DB on SQL doesn’t use much processing power.

In short, I think that the disadvantage for processing power of having the NAS on database server is less important than having the advantage that the NAS can directly communicate with the server without the network in the middle. I noticed that a lot of things go faster when launched from a client (remember: the NAS IS a client, but without user interface) directly on the server.

2. Window login

The NAS needs a windows-login to log into the database. This is because it is a service and it is not possible to define a database login in a service. The service needs a windows-login to launch it (like the login you use to login into Windows). So you need to create a login in the domain or on the server to do it. In general I prefer the administrator-account of the domain because it is possible that something has to be read or written on the network. At least with this login you know that the permissions are ok. Of course you need to be sure that a user cannot create some command-file in which there is a command to make him domain-admin and give that to the NAS to launch it. But I think that in most cases this is not a problem.

3. SQL-login (if you have a SQL database)

Now you have your Windows login, but this login has NO rights yet in SQL-server. So you need to create that Windows-login in SQL-server and make him sysadmin. See the manual on how to do that in SQL.

4. NAV-login

Now you are allowed in Windows and also in SQL (in case you have a SQL database), but you still are not allowed into Navision. So you need a Navision SUPER-user to create the account also in the Navision database (in the Navision client: Tools => Security => Windows login and give your Windows user the SUPER role. Now you have everything ok for the security.

5. Installing the NAS.

Take the installation CD, and launch the \Nas\setup.exe file. Just accept all defaults. But remember where the installed NAS-subdirectory is. You need this later.

6. NAS-services (run services.msc)

In general, I never use the default installation of the NAS (both nas.exe and nassql.exe). I just disable those services (properties of the service => Startup Type=Disabled).



Why do I do that?
  • I noticed that in some cases the NASSnapIn.msc doesn’t work, so I cannot control/change the
    NAS-settings in an easy way.
  • If you need multiple NAS, the next ones you need to install manually. So I just install the first one I use manually and then I just copy and change some parameters.

7. Manually install the NAS

I always use command-files to install/start and uninstall/stop the services. These are almost always the same, so I always copy the files and change some parameters.
These are the things to do:
  • Copy the installed NAS-subdirectory (remember I wrote to remember where the path where the NAS was installed?) where you want and give it the name you want.
  • Create the following command-files in the NAS-subdirectory:
    1. nasstart.cmd (for SQL-DB)
      nassql.exe appservername=TheNasName, NETTYPE=TCP, servername=TheSQLServer,
      database=TheSQLDatabase, company="The Company", nettype=tcp,
      startupparameter=”THEPARAMETER”, objectcache=40000, installasservice
      
      net start TheNasName
    2. nasstop.cmd (for SQL-DB) (you need the “:” at the start of the second line!)
      net stop TheNasName
      
      :nassql.exe appservername=TheNasName, uninstallasservice
    3. nasstart.cmd (for Navision-DB)
      nas.exe appservername=TheNasName, NETTYPE=TCP, servername=TheNAVServer,
      company="The Company", nettype=tcp, startupparameter=”THEPARAMETER”,
      objectcache=40000, installasservice
      
      net start TheNasName
    4. nasstop.cmd (for Navision-DB) (you need the “:” at the start of the second line!)
      net stop TheNasName
      
      :nas.exe appservername=TheNasName, uninstallasservice
    5. If you want to test the NAS from a DOS-prompt, remove the “, installasservice”, save the file and run it. The NAS will start but it will use your current login to connect to the database, so be sure you have the permissions. After that, you can add the “, installasservice” again.
    6. Parameters:
      • appservername: the name you give to the NAS. This is only the name to be used as reference in Windows. In Navision C/AL, this has no indications. Best avoid spaces or other strange characters in the name.
      • servername: the name of the Navision-server or SQL-server
      • databasename: (SQL only) the name of the database.
      • startupparameter: the startupparameter for the NAS. This value will be used in Navision C/AL. Later more info on this. Best to use only alfanumeric characters in the name and no spaces or other strange characters. If you want that the NAS does multiple things, you can put a list of startupparameters separated by a “,”. E.g. startupparameter=”JOB1,JOB2”
  • Now launch the nasstart.cmd. This will install the NAS as a service. After installing the service, put a “:” before the nas.exe or nassql.exe line. This comments the line. From now on, you can use the nasstart.cmd (and also nasstop.cmd) to start the service in some other command-file if needed.


    The NAS was successfully installed.

8. NAS-services (run services.msc)


Now we have to fix some things in the properties of the NAS-service. Open the properties of the new NAS-service you just created.
  • Tab General
    1. Startup Type:Automatic (this makes sure the service is started automatically when the server is started) (when just installing the NAS, this should be automatic).


  • Tab Log On (here you must put the Windows login you defined in SQL-security and Navision-security)
    1. This account: Put your windows useraccount in it
    2. Password, confirm password: put the password of the account


  • Tab Recovery (In case the NAS crashes, it will restart automatically)
    1. First failure, Second failure, Subsequent failures: Restart the service.
    2. Restart service after: 0 minutes


      When confirming it, you will get this message:



      It just means you need to restart the NAS-service:


9. How to control if the NAS works

  • Start the eventviewer (eventvwr.msc).
  • Click on Application and search for your NAS in the column Source. You should find 2 entries of type information



  • If you check the properties of those 2 events, you should see something like this:





    This means your NAS started up well and control has been given to function with ID 99 (=NasHandler) in codeunit 1.

10. C/AL

Now we have a NAS-service running, but the C/AL doesn’t know what to do. So we have to explain that to the C/AL. The NAS has a parameter (the “startupparameter=” to install the service) it sends into the Navision code. Now the Navision C/AL has to act upon it. Navision launches the function with ID 99 in codeunit 1. This function has an input-parameter that is text260. In this variable will be the input-parameter.
Or you can use the standard functionality already in Navision and you just need to do some setup for it (see the appropriate manuals for it).

Or you want to use your own functionality. In this case you need to program a little.
In this place you can add some code to explain what Navision should do:
  IF CGNASStartedinLoop = FALSE THEN
    CASE Parameter OF
//> START
      'THEPARAMETER': CODEUNIT.RUN(CODEUNIT::”Some CodeUnit”);
//< STOP
      'OSYNCH','JOBQUEUE':
In general a singleinstance codeunit is launched that installs something and then goes in sleep and waits for some event to start working. An event could be a timer-event, the arrival of a message in a message queue or named pipe or also something else.

11. Things to avoid in C/AL for a NAS

You should NOT use dialogbox, confirm, strmenu in Navision. The NAS doesn’t like this and gives an error. You will get an error like this:



To avoid this kind of errors, you need to put some code like this (an example you can find in codeunit 90:”Purch.-Post”:
    IF GUIALLOWED THEN
      Window.OPEN(
And please, don’t ask why codeunit 80:”Sales-Post” doesn’t have this test.

12. Objects to avoid in C/AL for a NAS

I made an extra point of this so it is very clear. Some objects (FORMS and DATAPORTS) cannot be used with the NAS. To be sure you remember:

DATAPORTS CANNOT BE RUN WITH THE NAS!!!!

This is the error you get:



How to solve it? Create a report or a codeunit and use a FILE to read or write a file. But you can’t count on the automatic processing provided by a dataport.

13. Messages and errors in the C/AL code.

These are no special problem. The messages are logged in the eventviewer as type information and the C/AL continues.



This was my MESSAGE-statement:
MESSAGE('The NAS has been started.');
Also the errors are logged in the eventviewer as type warning and of course the processing stops with a error.
If it is code directly launched from function NasHandler in codeunit 1, the NAS will crash. And if you put the correct properties in the service, the service will restart automatically.
If it is code in the singleinstance codeunit, the NAS-service will NOT crash. The singleinstance codeunit should be able to restart itself through event-triggers. Later follows an example on how to do it.



This was my ERROR-statement:
ERROR('The NAS has an ERROR-statement in it.');

14. The singleinstance codeunit.

This is a codeunit with property SingleInstance=Yes. (To know what it means, just read the online help or the manual).
This is how to create a singleinstance codeunit that is triggered every N seconds. This can be used to check if there something to be done, and then do it.
In the singleinstance codeunit, you need to define a global:
autNavisionTimer of type automation and subtype: 'Navision Timer 1.0'.Timer
This global needs property WithEvents=Yes.
This property will create 2 extra functions:
autNavisionTimer::Timer(Milliseconds : Integer)
autNavisionTimer::TimerError(ErrorString : Text[1024])
In the function “autNavisionTimer::Timer” you need to put the code you want to trigger every N seconds. Best is to create a function and put the code in there and just call the function from the trigger. Remember that if you delete the global, you will lose all code in that trigger!
If there is an error in this code, the NAS will NOT crash. The timer-function of the global variable will restart the function as if no error has happened.

In the OnRun-trigger of the codeunit, you need to initialize this automation:
OnRun()
CREATE(autNavisionTimer);
autNavisionTimer.Interval(10000); // this will trigger every 10 seconds
autNavisionTimer.Enabled(TRUE);
Remember also that an error in the OnRun-trigger will crash the NAS-service. Windows will restart the NAS-service again in this case (at least if the properties on the services are set correctly).