views:

650

answers:

2

I am trying to create a Task Scheduler task to start my SQL Server 2005 instance every morning, because something stops it every night. This is a temporary solution until I can diagnose the stoppage.

I created a task to run under my admin user, and to start the program, cmd with the arguments /c net start mssqlserver. When I manually run the command, in a console under my admin user, it runs, but when I try to manually execute the task, it logs the following message, and the service remains stopped:

action "C:\Windows\system32\cmd.EXE" with return code 2.

Any suggestions?

+1  A: 

Use the NET command:

To start a service, type: net startservice

To stop a service, type: net stopservice

To pause a service, type: net pauseservice

To resume a service, type: net continueservice

See this Microsoft article on additional details: Microsoft Article

In addition I would look at the Windows Event logs (Application and System) for details as to why SQLServer is stopping in the first place.

John Dyer
John, I am already using the NET START command, and stated so in my question, which is not how to start the service, but how to do it from Task Scheduler.
ProfK
+1  A: 

I would recommend opening the Services MMC snap-in (just run services.msc), finding the service and modifying the properties of the service to restart automatically when the service fails.

  1. Open the Services MMC snap-in (run services.msc)
  2. Locate the service. If you installed a default instance of SQL Server 2005 that would be "SQL Server (MSSQLSERVER)". If you installed a named instance the name would be in the parenthesis.
  3. Right-click on the service and select "Properties".
  4. Switch to the "Recovery" tab.
  5. Set the options for first, second and subsequent failures as desired.
  6. Click "OK".

And John Dyer is also right about looking in the Windows Event logs for details on why SQL Server stopped (run eventvwr.exe).

Jim Clark