title: SQL Maintenance Cleanup task not deleting any files, SQL installed on a DC
body: <p>The generic problem is as listed here <a href="https://stackoverflow.com/questions/5327282/sql-maintenance-cleanup-task-working-but-not-deleting">SQL Maintenance Cleanup Task Working but Not Deleting</a> but no solutions applicable. Environment: Windows Server 2012R2, AD DS (with policies of course), RDSH/TS Licensing, 1C-server. The primary problem is SQL Server generating insane amount of events per backup plan run, recording a pair of 18456+17052 errors per file to delete. Errors are as follows:</p>
  
  <ul>
  <li>17052: [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'DOMAIN\mssql_srv'</li>
  <li>18456: Reason: Could not find a login matching the name provided. [CLIENT: 192.168.x.x] (matches localhost)</li>
  </ul>
  
  <p>Given that each pair of errors appears once per file to delete (there are about 6000 files already!), the algorithm looks like this:</p>
  
  <ul>
  <li>First, backup plan task runs <code>xp_delete_file</code>, it enumerates all the files in target folder;</li>
  <li>Second, each file is deleted by creating a separate connection to machine with service's credentials;</li>
  <li>Each connection fails due to whatever restrictions default DC policy applies, generating the pair of events. Of course the file remains in place.</li>
  </ul>
  
  <p>The workaround is of course assign file delete task to a local script run as system, for example, but the very reason of why does SQL server fail to delete a file remains unknown. Permissions have been checked and verified that both SQL Server Agent and SQL Server service accounts have full control to the folder.</p>