views:

591

answers:

1

Hi there,

Right now i have some sort of services application on windows server 2003 for inputting data from devices into database.

Sometimes the services fail due to data error or anything else (database connection problem, internet connection down, etc) which i have to restart the services, right now the solution i provide for this problem was a simple batch command using NET START/STOP command that scheduled every 1 hour.

I then take a look at recovery tab on service properties, there was an option to restart the services, which i want to know was how to test it? Such as, how Windows know the services was failed? And the most important was how to know that services successfully restarted when failure occur (based on recovery setting)?

PS: I didn't have access to the code

Thanks

+2  A: 

The service console's auto restart kicks in when a service crashes from an unhandled exception. (Some part of your code throws an exception, but nothing catches it, and it bubbles all the way up and out of the main function.)

If you have control over the code, it might be better to put in some try/catch blocks around the areas that tend to cause problems and handle errors more gracefully. You could also put a try/catch around the main entry point of the application, to catch and try to handle any unhandled exceptions from the code.

If you can't control the code, you can test the auto service recovery by forcing one of these errors to occur. If you service crashes in the event of a connection problem, you can force this by unplugging the network cable on the computer.

Andy White
too bad i can't test it right now, since it's on our production server and i didn't have the access to the code, but i'll try deploying development server soon. Btw how to know service has restarted in case of failure?
Dels
Do you have any logging setup on the service? If not, you can just check the service console to see if it is running after a failure.
Andy White