日期:2014-05-17 浏览次数:20460 次
DECLARE @temp TABLE([state] NVARCHAR(255))
INSERT @temp([state])
EXEC master.dbo.xp_servicecontrol N'QUERYSTATE',N'SQLSERVERAGENT'
IF(SELECT TOP(1) [state] FROM @temp) <> 'Running.' --Running./Stopped.
BEGIN
EXEC master.dbo.xp_servicecontrol N'START',N'SQLSERVERAGENT'
END
IF object_id('tempdb..#temp', 'u') IS NOT NULL DROP TABLE #temp
CREATE TABLE #temp ([state] VARCHAR(255))
DECLARE @sql VARCHAR(1000)
SET @sql = '
INSERT INTO #temp([state])
EXEC master.dbo.xp_servicecontrol N''QUERYSTATE'',N''SQLSERVERAGENT''
'
EXEC (@sql)
IF(SELECT TOP(1) [state] FROM #temp) <> 'Running.' --Running./Stopped.
BEGIN
EXEC master.dbo.xp_servicecontrol N'START',N'SQLSERVERAGENT'
END