Restart NAS when modify field in NAV

johannajohanna Member Posts: 369
Dear All,

Could I add C/AL code to restart NAS service automatically when user modify field in NAV?
How to get NAS status (start/stop) with C/AL Code?
Please help..
Thank you..
Best regards,

Johanna

Answers

  • ta5ta5 Member Posts: 1,164
    Hi Johanna
    Try to solve this by organisation. This means changing objecs should not take place in production db, deploy by fob and restart nas after that. Person in charge of deploying should work with checklist. This is not exactly the answer to your question, but works in a lot of projects.

    Hope this helps
    Thomas
  • SPost29SPost29 Member Posts: 148
    This is a great question!
    I have 3 NAS's on three different servers. I would love to be able to stop/restart them from one place- one click.
    Now I have to go to the 3 different servers and do each seperately.
    How can we do this from within Nav?
    Thanks
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Commands to start and stop the nas are
    net start TheNasName
    net stop TheNasName

    So you can try by opening the command.exe using shell commands and execute above commands..
  • ta5ta5 Member Posts: 1,164
    Good answer, but my question is still why somebody want to do this :?
  • SogSog Member Posts: 1,023
    ta5 wrote:
    Good answer, but my question is still why somebody want to do this :?
    because a developer has connected to nav trough his local client with a testdb running on a testserver somewhere.
    Instead of loggin into the server and doing net stop/start because he changed the singleinstance codeunit.
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • SPost29SPost29 Member Posts: 148
    The situation:
    I am on my Dev machine
    I am in NAV connected to the live DB
    I import a fob to the Live DB
    I want to restart my NAS's (which are on 3 seperate physical servers)
    I have to individually connect to the first server
    Open the application services
    stop and start the NAS
    disconnect from that server
    connect the next server and repeat

    I would like to press a button in Nav or on my desktop and have the process find each server
    and stop and start the NAS


    Mohana
    Thank you for the commands (I presume they are run when on the specific server)
    Can I run some variation remotely
    How could I tell your commands what server each NAS is on.

    Thanks
  • matthiasclaesmatthiasclaes Member Posts: 18
    I think this is what you actually are looking for:

    sc \\computername stop NAS-SQL-ServiceName

    Mix this with the C/AL SHELL function, and you control your services from Navision.
    For me, I use a batch file from my desktop.
    My NAV client is on a random citrix server, SQL and NAS both on their own dedicated machine (all VM'd). Your AD account requires the necessary permissions to stop and start services, tough.


    When I want to test, I double-click the batch file om my desktop, resulting in:

    sc \\NAS-SERVER stop NAS-SQL_DevDatabase
    sc \\NAS-SERVER start NAS-SQL_DevDatabase

    And yeah, I've thought about ways to ensure the production NAS auto-restarts after it gets disconnected from the database after importing fobs, but this will require some kind of second 'guardian' service or scheduled task. Haven't got a reliable system worked out.
  • SPost29SPost29 Member Posts: 148
    Thanks for the code.
    I will try to put this in a Nav function with a call to SHELL or something and report back
  • bbrownbbrown Member Posts: 3,268
    SPost29 wrote:
    Thanks for the code.
    I will try to put this in a Nav function with a call to SHELL or something and report back

    I've not used it but there's an Automation component that shows up called "nascontrol 1.0 Type Library" with some interesting properties and functions. Maybe you could build something from that?
    There are no bugs - only undocumented features.
  • johannajohanna Member Posts: 369
    Dear all,

    I have found the solution of this issue.
    I add new variable Automation 'AutoWindowsScript': 'Windows Script Host Object Model'.WshShell
    then add code in OnModify Table :

    //STOP SERVICE NAS - START
    CREATE(AutoWindowsScript);
    AutoWindowsScript.Exec('NET STOP "Navision Application Server NAS"');
    CLEAR(AutoWindowsScript);
    //STOP SERVICE NAS - FINISH

    //DELAY PROCESS - START
    COMMIT; // Commit the changes to the database.
    SLEEP(5000); // Release locks for a specified duration.
    SELECTLATESTVERSION; // Retrieve the most current database version before the process is run.
    //DELAY PROCESS - FINISH

    //START SERVICE NAS - START
    CREATE(AutoWindowsScript);
    AutoWindowsScript.Exec('NET START "Navision Application Server NAS"');
    CLEAR(AutoWindowsScript);
    //START SERVICE NAS - FINISH

    Thanks all :)
    Best regards,

    Johanna
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    It's also possible to connect to another server via Application Server Manager SnapIn. That means you don't have to switch / logon to every single server. So, I see no issues.
    "Money is likewise the greatest chance and the greatest scourge of mankind."
Sign In or Register to comment.