SQL Server Service restarting throuh Job

  • hi can any give the code to restart services through code in SQL server 2005 and 2008

  • Well, you can shut SQL down from a SQL Agent job, but you won't be able to restart it. Stopping SQL Server stops SQL Agent.

    You can use Windows Scheduler and the NET STOP and NET START commands.

    Why do you need this? Restarting SQL is generally not something done so often that a scheduled task needs to be used.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • I agree with Gila Monster but if you really need to you can create a .bat file and then set it up as a scheduled task.

    NET STOP SQLSERVERAGENT

    NET STOP MSSQLSERVER

    NET START MSSQLSERVER

    NET START SQLSERVERAGENT

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

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