My lab machine is my playground. Other than my real-world client’s problem, many blogs have come from my lab machine because I keep on breaking something or another on my server. Once I found that I was unable to start SQL Server Agent service for one of the SQL Server instances. In this blog, we would learn how to fix error Failed to initialize SQL Agent log (reason: Access is denied)
As the first step of troubleshooting, I went to the SQL Server Errorlog folder to check for errors. The SQL Server Errorlog default path is,
<Drive>:\Program Files\Microsoft SQL Server\MSSQL1x.<InstanceID>\MSSQL\Log\SQLAGENT.OUT
Surprisingly when I went to the above location, I could not find the latest SQL Agent log. It only showed the older ones. We tried to start the SQL Agent service from service control manager and got the below error.
I still didn’t see the SQL Agent log. I tried to investigate the Event Viewer logs and found the below info in application event log.
Information SQLSERVERAGENT 102 Service Control SQLServerAgent service successfully stopped.
Error SQLSERVERAGENT 324 Alert Engine Failed to initialize SQL Agent log (reason: Access is denied).
Now, even the above error is not helping us much. But it revealed few vital clues for us.
- We have a permission issue.
- And it is related to SQL Agent Log.
I went ahead and checked the required permission on the SQL Agent log folder and they all looked fine. From my experience, for any “Access Denied” message the next tool which I prefer is Process Monitor (Procmon). I will not deal with procmon on this blog. So, let’s try to start SQL Agent in CMD Prompt and use some startup parameters.
I tried starting SQL Agent using the below command,
<Drive>:\Program Files\Microsoft SQL Server\MSSQL1x.<InstanceID>\MSSQL\Binn\SQLAGENT.exe -i MSSQLSERVER -c -v
- -i = Instance name
- -c = console mode
- -v = verbose mode
I got the below errors when we started SQL Agent using the above command.
This error looks similar to the error we saw in event viewer. But read again!! I’m sure you might have missing reading the first line.
Unable to rename C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Log\ to C:\Program Files\Microsoft SQL Server\MSSQL13.1 (reason: Access is denied)
If you closely notice, SQL Agent service trying to rename the above folder! After spending a few moments decrypting this, I was finally able to get the logic. Hear me out and let me know if my logic was correct.
The current SQL Agent log file is called as “SQLAGENT.OUT” Every time we restart SQL Agent service, the SQLAGENT.OUT is renamed to SQLAGENT.1 and a new SQLAGENT.OUT file is created and eventually becomes the current log file.
In the above scenario, SQL Agent thinks the current log file name is- “MSSQLSERVER\MSSQL\Log”
C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Log
This is because we have DOT separator as an extension of a file. So, SQL Agent is trying to rename MSSQLSERVER\MSSQL\Log to .1 as per the renaming logic and thus failing. In an ideal scenario, it should look like,
Rename – C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Log\SQLAGENT.OUT to
C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Log\SQLAGENT.1
WORKAROUND/SOLUTION
It looks like the SQL Agent Log file name is missing from the string and we had to edit that to fix the issue. From my experience, I know that this information is stored in,
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL13.MSSQLSERVER\SQLServerAgent\ErrorLogFile
When we went to the above-mentioned registry location we could that the SQL Agent log file name was missing.
After we added the log file name we were able to start SQL Agent successfully.
Reference: Pinal Dave (https://blog.sqlauthority.com)
First appeared on SQL SERVER – SQL Server Agent Not Starting – Failed to Initialize SQL Agent Log (Reason: Access is Denied).