Using SQL server 2012 I got the following error from my Windows Server 2012 R2
OpenSQLServerInstanceRegKey:GetRegKeyAccessMask failed (reason: 2).
Using SQL server 2012 I got the following error from my Windows Server 2012 R2
OpenSQLServerInstanceRegKey:GetRegKeyAccessMask failed (reason: 2).
I found my answer - SQLServer Express edition does not support SQL Server Agent.
I encountered the same error in the Application log on my local workstation when trying to start the SQL Agent.
The SQLAGENT.OUT file didn't exist in the Log path, mentioned in an earlier answer. I wondered if the service account for the agent lacked the permissions to access this Log folder...
I tried adding the service account "NT Service..." to the list of approved users for that folder. No joy - couldn't see the account in the list of users on the workstation.
So, I changed the service account of SQL Agent to match that of the SQL Server service. Bingo! The Agent started up, and the SQLAGENT.OUT file appeared in the log folder.
Not too worried about any security implications of making the service accounts the same for both engine and agent, as it's my local dev workstation...
You need to delete the SQLAGENT.OUT log file from the logging directory (yours may be slightly different):
C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Log\SQLAGENT.OUT
It's a known issue fixed in SQL Server 2012 SP1 but I didn't have time to mess around with upgrading the database so I applied the above workaround instead and was able to start SQL Agent successfully.
Click here for more info.
I restart the computer three times,
and find that though the Server Agent can't be started, strangely I can connect to my database in SQL management studio...
Database can be connected and used is what I care, so I didn't make mopre try to start the SQL Server Agent.