I need a simple batch command which will wait until specified service (actually, SQL Server) is finished starting. See, the bat file runs some non-service executables which attemp to connect to the SQL server on start. And they fail.
I tried to help (” /?” key) some Windows Shell commands but they do not seem to respond with an action I need.
Unfortunately, this command doesn’t exist. The
sccan start and stop a service and it can query the status of a service (see this answer). But even when you query, you will only get “Service is running”; there is no way to tell how far the service got in its startup.There are two workarounds:
The first approach will help but it won’t completely solve the problem; when the server is under load, the startup can take longer.
For the second approach, use a loop which times out (pseudocode):
For additional safety, you could add a
sc queryin there to make sure the service didn’t fail.