forked from Azure-Player/SQLCop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Agent Service.sql
49 lines (39 loc) · 1.35 KB
/
Agent Service.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
ALTER PROCEDURE [SQLCop].[test Agent Service]
AS
BEGIN
-- Written by George Mastros
-- February 25, 2012
-- http://sqlcop.lessthandot.com
-- http://wiki.lessthandot.com/index.php/Find_out_if_SQL_Agent_running
SET NOCOUNT ON
Declare @Output VarChar(max)
DECLARE @service NVARCHAR(100)
Set @Output = ''
If Convert(VarChar(100), ServerProperty('Edition')) Like 'Express%'
Select @Output = 'SQL Server Agent not installed for express editions'
Else If Is_SrvRoleMember('sysadmin') = 0
Select @Output = 'You need to be a member of the sysadmin server role to run this check'
Else
Begin
SELECT @service = CASE WHEN CHARINDEX('\',@@SERVERNAME)>0
THEN N'SQLAgent$'+@@SERVICENAME
ELSE N'SQLSERVERAGENT' END
Create Table #Temp(Output VarChar(1000))
Insert Into #Temp
EXEC master..xp_servicecontrol N'QUERYSTATE', @service
Select Top 1 @Output = Output
From #Temp
Where Output Not Like 'Running%'
Drop Table #Temp
End
If @Output > ''
Begin
Set @Output = Char(13) + Char(10)
+ 'For more information: '
+ 'http://wiki.lessthandot.com/index.php/Find_out_if_SQL_Agent_running'
+ Char(13) + Char(10)
+ Char(13) + Char(10)
+ @Output
EXEC tSQLt.Fail @Output
End
END;