Troubleshooting Guide: SQL Server Error 5111 – File Activation Failure
Why This Error Happens
Error 5111 occurs when SQL Server 2025 cannot locate or access the physical database file (.mdf, .ndf, or .ldf) specified in the file path during database attachment or startup. This is typically caused by the file being moved, renamed, or deleted, incorrect permissions on the file or parent directory for the SQL Server service account, or the file path referencing a drive/location that is no longer accessible (such as a disconnected network share or offline disk). In some cases, this error also surfaces when the file is held exclusively by another process, including antivirus software or a conflicting SQL Server instance.
Step-by-Step Resolution Guide
Step 1: Verify the Physical File Path and Existence
- Open File Explorer or PowerShell and navigate to the directory specified in the error message (e.g.,
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\DATA\). - Confirm the exact file name and extension match what SQL Server expects; watch for case sensitivity or extra spaces.
- Run
Get-ChildItem -Path "C:\SQLData\" -Filter "*.mdf"in PowerShell to list actual files present. - If the file is missing, restore it from backup or locate it on a different drive/volume.
Step 2: Validate NTFS Permissions for the SQL Server Service Account
- Right-click the database folder (e.g.,
D:\SQLData\) and go to Properties > Security. - Ensure the SQL Server service account (commonly
NT Service\MSSQLSERVERor a custom domain account) has Full Control or at minimum Modify, Read, and Write permissions. - Use
icacls "D:\SQLData" /grant "NT SERVICE\MSSQLSERVER:(OI)(CI)F"in an elevated Command Prompt to reset permissions if needed. - Restart the SQL Server service via SQL Server Configuration Manager after applying changes.
Step 3: Check for File Locks or Conflicting Processes
- Open Resource Monitor (
resmon.exe) and search the CPU tab for the file name under “Associated Handles” to identify locking processes. - Temporarily disable real-time antivirus scanning on the SQL data directory to rule out interference.
- Ensure no other SQL Server instance or external backup tool (like VSS writers) is holding an exclusive lock on the .mdf/.ldf file.
Step 4: Reattach the Database Using Correct Syntax
- Open SQL Server Management Studio (SSMS) and run the following, updating paths as needed:
CREATE DATABASE YourDB ON
(FILENAME = 'D:\SQLData\YourDB.mdf'),
(FILENAME = 'D:\SQLData\YourDB_log.ldf')
FOR ATTACH;
- If the log file is missing or corrupted, use
FOR ATTACH_REBUILD_LOGinstead (only for non-production, trusted databases).
Step 5: Confirm Drive and Volume Availability
- If the database resides on a mapped network drive or SAN volume, verify connectivity using
Test-Path "\\NetworkShare\SQLData\"in PowerShell. - Ensure the drive letter assignment hasn’t changed after a Windows Server 2025 update or reboot via Disk Management (
diskmgmt.msc).
Alternative or Verification Steps
- After applying fixes, run
sp_helpdb YourDBor check SQL Server Logs (via SSMS Object Explorer > Management > SQL Server Logs) to confirm the database status shows ONLINE with no further 5111 errors. - If reattachment continues to fail, restore the database from the most recent valid backup using
RESTORE DATABASE YourDB FROM DISK = 'D:\Backups\YourDB.bak' WITH RECOVERYas a fallback solution.