How to fix Error 3737 on Windows Server 2025 / Windows 11

Troubleshooting Guide: SQL Server Error 3737 — “Could not delete file ‘%ls'”

Why This Error Happens

This error typically occurs during a database backup, restore, or file removal operation (such as DBCC SHRINKFILE with EMPTYFILE, or dropping a database) when SQL Server’s service account lacks sufficient NTFS permissions on the target file or folder. It can also happen if the file is locked by another process (antivirus scanners, backup agents, or a lingering SQL Server handle), is marked read-only, or resides on a volume/path that no longer exists or is inaccessible due to storage misconfiguration. Less commonly, file system corruption or an improperly dismounted volume prevents the delete operation from completing.

Step-by-Step Resolution Guide

Step 1: Verify File and Folder Permissions

  • Locate the exact file path referenced in the error (check the SQL Server Error Log at C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG for the full %ls value).
  • Right-click the file/folder, go to Properties > Security, and confirm the SQL Server service account (e.g., NT Service\MSSQLSERVER or a custom domain account) has Full Control.
  • Grant permissions via PowerShell if needed:
  icacls "D:\SQLData\YourFile.mdf" /grant "NT SERVICE\MSSQLSERVER:(F)"

Step 2: Check for File Locks and Exclude from Antivirus

  • Use Process Explorer (Sysinternals) or openfiles /query to identify if another process has an open handle on the file.
  • Add SQL Server data/log directories to your antivirus and Windows Defender exclusion list to prevent real-time scanning from locking files:
  Add-MpPreference -ExclusionPath "D:\SQLData"
  Add-MpPreference -ExclusionPath "D:\SQLLogs"
  • Stop any third-party backup agents temporarily and retry the operation.

Step 3: Confirm the Path Exists and Is Writable

  • Verify the drive/volume referenced in the error is online using Disk Management or Get-Disk in PowerShell.
  • Ensure the file is not flagged as read-only:
  attrib -R "D:\SQLData\YourFile.ndf"
  • If the volume uses storage spaces or a SAN/NAS mount, confirm connectivity and that the drive letter/mount point hasn’t changed.

Step 4: Restart SQL Server Service to Release Stale Handles

  • Open SQL Server Configuration Manager, right-click the SQL Server (MSSQLSERVER) service, and select Restart.
  • This clears any orphaned internal file handles that may be causing the delete to fail silently.
  • Re-run the operation (e.g., DBCC SHRINKFILE, DROP DATABASE, or backup job) immediately after restart.

Alternative or Verification Steps

  • Re-run the original command (e.g., ALTER DATABASE ... REMOVE FILE or DROP DATABASE) and check the Error Log to confirm Error 3737 no longer appears.
  • If the issue persists, manually delete the file via File Explorer or del command after taking the database offline, then run DBCC CHECKDB to confirm no orphaned references remain in the system catalog.