There are several reasons for the error mentioned in the blog title. In this blog, we would learn about one of the causes of error Unable to start service SQLSERVERAGENT on a server.
When my client contacted me, they were in process of changing the hardware/drives and the path of SQL Server related files. After making changes to the path of SQLAgent.OUT file, they were unable to start SQL Server Agent Service. Here is the screenshot when they tried starting SQL Server Agent service via SQL Server Management Studio.
Here is the text of the above error message.
Unable to start service SQLSERVERAGENT on server ABCLProdSQLServer. (mscorlib)
When I joined the call with them, I checked the event log, I found below message.
Failed to initialize SQL Agent log (reason: Access is denied).
From above, we can say that SQL Server Agent is trying to write to a log file but unable to do so. Now, we needed to find out the location and file name. Below is the T-SQL code to get the location.
USE [msdb] GO EXEC sp_configure 'Agent XPs', 1 GO RECONFIGURE WITH OVERRIDE GO EXEC msdb.dbo.sp_get_sqlagent_properties -- CHECK FOR errorlog_file column
Check for an errorlog_file column. When I checked the value for my client, it was
H:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\Log
Above file was not getting generated due to an error in event log. Wait a second. Look closely, looks like my client missed SQLAgent.OUT file name over there. We already have a FOLDER called LOG and that’s why we can’t take a file with the same name.
Now, since we have found that this was due to an incorrect value set for the SQL Server Agent log file, we need to correct the value. There are multiple ways to do it.
- Use below T-SQL
USE [msdb] GO EXEC sp_configure 'Agent XPs', 1 GO EXEC msdb.dbo.sp_set_sqlagent_properties @errorlog_file=N'H:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\Log\SQLAgent.out' GO
- We can also modify the registry directly using “Start > Run > Regedit” and navigating to the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQLSERVER\SQLServerAgent
Highlighted piece is the combination of the SQL version and instance name. MSSQL13 stands for SQL Server 2016. MSSQL12 is for SQL Server 2014 and so on and so forth.
We need to change a value for “ErrorLogFile” and provide a valid file name.
Once we made above changes, SQL Server Agent got started without any further error.
Reference: Pinal Dave (https://blog.sqlauthority.com)
I had a similar issue with sql 2019 in Server 2019. It was a test environment. However, in my case the first query returned a
“Msg 15123, Level 16, State 1, Procedure sp_configure, Line 62 [Batch Start Line 2]
The configuration option ‘Agent XPs’ does not exist, or it may be an advanced option.
Msg 15281, Level 16, State 1, Procedure msdb.dbo.sp_get_sqlagent_properties, Line 0 [Batch Start Line 6]
SQL Server blocked access to procedure ‘dbo.sp_get_sqlagent_properties’ of component ‘Agent XPs’ because this component is turned off ”
Since it was a test environment I had accepted the default logins for the sql server agent which was “NT SERVICE\SQLSERVERAGENT”. I added this account to the local administrators group in the server. After that the sql server agent started without issues.