Restarting SQL Service from SQL job

  • I am attempting to restart the SQL service (and SQL agent) from within a SQL job. I have the commands to do the starting and stopping of the services but I can't find a way to get a shell that SQL doesn't stop as soon as the agent service is stopped. I am curious to know if there is a way to get a shell started from a SQL job but that won't terminate once the SQL agent is stopped. I have tried running a batch file from the Operating System type step and was working on testing an ActiveX script but both of these terminate once the agent is stopped. I can get the service to stop by doing this but once this happens the start service step won't run. Just to make sure here is my current setup:

    SQL job using the "Operating system (CmdExec)" type

    --- This run a bat file c:\test.bat

    In this bat file are these steps

    net stop "SQL Server (MSSQLSERVER)"

    net start "SQL Server (MSSQLSERVER)"

    net start "SQL Server Agent (MSSQLSERVER)"

    As I said earlier this get to the net stop part of the bat file and then stops. Any suggestions on how to get this working?

  • Try this:

    start c:\test.bat

  • Wow, and here I was working on some elaborate scheme to get this working. I guess the start creates a shell outside of SQL. Thanks for this you just saved me at least a couple of hours hitting my head against my desk.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply