Follow sqlserver-dba.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

SQLServer-DBA.com Links

Dba_db2_button

dba-ninja.com

SQL Server DBA Jobs

How to check if SQL Server Agent is running using t-sql

08 October,2020 by Tom Collins

Question: I want to check if SQL Server Agent is running using t-sql.    I know I can check through the services.msc or other methods such as Powershell scripts to report on the SQL Server Agent status , but the requirement is to extract this information via t-sql. Do you have a script using t-sql to get the SQL Server Agent Status?

 

Answer: If you check the SQL generic Refresher  program in the sysprocesses list , it is possible to establish the SQL Server Agent status through t-sql.  The SQL Generic Refresher  is an app program. When the SQL Server Agent starts a connection appears with the Program name SQL generic Refresher

 

IF EXISTS(
SELECT 1 FROM MASTER.dbo.sysprocesses WHERE program_name = N'SQLAgent - Generic Refresher')
BEGIN
SELECT SERVERPROPERTY('ServerName') AS 'SQL_Server_Instance', 'Running' AS 'SQL_ServerAgent_Status'
END
ELSE
BEGIN
SELECT SERVERPROPERTY('ServerName') AS 'SQL_Server_Instance', 'Stopped' AS 'SQL_ServerAgent_Status'
END

Read more on SQL Server Agent 

Disaster Recovery Powershell Script to check for failed Windows services

Powershell script - Get the SQL Server Instance status with Get-Service

SQL Server - Working with Windows Services Examples and Powershell


Author: Tom Collins (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on How to check if SQL Server Agent is running using t-sql


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer