SQLTeam.com | Weblogs | Forums

Maintenance Plan job failing with access denied for NT SERVICE\SQLSERVERAGENT


I used the Maintenance Plan Wizard under SQL2014 to create a simple maintenance plan that once a week:

  1. Check Database Integrity including indexes
  2. Rebuild Index
  3. Clean Up History

When the job runs this is the error message. Any ideas why it is failing? I did check and NT SERVICE\SQLSERVERAGENT is a member of the sysadmin group as it should be

Executed as user: NT SERVICE\SQLSERVERAGENT. ...2 01:01:31.89 Source: Check Database Integrity Executing query "USE [vc2] ".: 50% complete End Progress Error: 2016-05-12 01:01:51.89 Code: 0xC002F210 Source: Check Database Integrity Execute SQL Task Description: Executing the query "DBCC CHECKDB(N'vc2') WITH NO_INFOMSGS " failed with the following error: "A database snapshot cannot be created because it failed to start. A database snapshot cannot be created because it failed to start. CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'E:\vc2.mdf_MSSQL_DBCC29'. The database snapshot for online checks could not be created. Either the reason is given in a previous error or one of the underlying volumes does not support sparse files or alternate streams. Attempting to get exclusive access to run checks offline. The database could not be exclusively locked to perform the operation. Check statement aborted. The database could not be checked as a database snapshot could not be created and the database or table could not be locked. See Books Online for details of when this behavior is expected and what workarounds exist. Also see previous errors for more details.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.


Any reason why NT SERVICE\SQLSERVERAGENT cannot create that file? Does E: exist (from that user's perspective - particularly if it is a Mapped Drive, rather than a physically connected drive)

Permissions OK on the Root of E: ?

Perhaps ignore the specific error message "Access is denied" in case that is a red-herring. Is the drive Full, Offline, Slow or anything else peculiar like that?


From Windows Server 2008 and above - the root of drives are blocked by default and you cannot create files in those locations. When CHECKDB tries to create the snapshot it fails because it is attempting to create that in the root directory of the drive.

To fix this - move the database files to a folder (with appropriate permissions) or disable UAC on the server. Disabling UAC may not work but moving the files to a folder on the E:\ drive will work.