Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Agent automatic restart 1

Status
Not open for further replies.

snarky

Technical User
Oct 30, 2003
5
US
I'm running SQL 2000. I want SQL Agent to restart automatically when SQL itself restarts.

I thought that checking off the box 'Auto Restart SQL Server Agent if it stops unexpectedly' (SQL Agent > Properties > Advanced tab) would do it but it doesn't appear to be working. If I stop the server and start it up again, SQL Agent doesn't start up again (it was running just prior to me stopping SQL server). I know that I can use Windows Services but I thought that would only take effect once the server (OS) is rebooted. I want it to come back regardless of how the server is stopped.

Can anyone shed some light on this one for me? Thanks in advance for any help you can provide.
 
Open your SQL Server Service Manager.

Make sure the SQL Server Agent Service has the
Auto-start service when OS Starts check box checked too.

Thanks

J. Kusch
 
Hey JayKusch -

Thanks for the quick reply. I checked off that box and tested it again - still doesn't work. Here's what I'm doing to test:

- Make sure all 'autostarts' are checked off (SQL server properties, SQL Agent properties, Services, etc).
- Make sure SQL Agent is running.
- Go to the Services Manager and stop SQL Server.
- Go to the Services Manager and start SQL Server.

I want to see SQL Agent come back on automatically, but it doesn't. There's no reboot involved here.

Any more ideas?
 
When you say "checked off" you mean you are enabling the option by checking the box ... True?

Thanks

J. Kusch
 
Yes, I'm enabling the autostart options. Sorry for the vagueness there.
 
This may help ... Run it in Query Analyzer against the Master DB. Make sure 'scan for startup procs' option is set at 1. can check that by running sp_configure.
Code:
CREATE PROC AutoStart_SQLAgent
AS
BEGIN
 DECLARE @Err int, @Msg varchar(100), @ServiceName sysname

 SET @ServiceName = 'SQLServerAgent'

 EXEC master.dbo.xp_servicecontrol 'START', @ServiceName 
  SET @Err = @@ERROR
  IF @Err = 0
    BEGIN
      RAISERROR ('Successfully started SQL Server Agent', 1, 1) WITH LOG
    END
   ELSE
    BEGIN
     SET @Msg = 'Error occured while starting SQL Server Agent. Error code: ' + STR(@Err)
			RAISERROR (@Msg, 18, 1) WITH LOG
    END
END
GO

EXEC sp_procoption 'AutoStart_SQLAgent', 'startup', 'true'
GO

Thanks

J. Kusch
 
I'm going to try it this morning. I'll keep you posted!

 
Worked like a charm! Thanks for your help Jay!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top