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

Troubleshooting Guide: SQL Server Error 5105 – File Activation Error

Why This Error Happens

Error 5105 occurs when SQL Server cannot locate, access, or create the physical file specified in a database operation, typically because the file path is invalid or the file has been moved or deleted. This is frequently caused by the SQL Server service account lacking NTFS permissions on the target folder, or because the drive/directory referenced in the command no longer exists. It can also surface during database attach operations when the specified .mdf or .ldf path doesn’t match the actual file location on disk.

Step-by-Step Resolution Guide

Step 1: Verify the Physical File Path

  • Open File Explorer and navigate to the directory referenced in the error (e.g., C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\DATA\).
  • Confirm the exact file name and extension (.mdf, .ndf, .ldf) match what SQL Server is expecting.
  • If the file was renamed or moved, update your T-SQL command to reflect the correct path.

Step 2: Check NTFS Permissions on the Folder

  • Right-click the data folder, go to Properties > Security, and confirm the SQL Server service account (e.g., NT Service\MSSQLSERVER) has Full Control.
  • If missing, click Edit > Add, type the service account name, and grant Read, Write, and Modify permissions.
  • Restart the SQL Server service afterward via services.msc or by running net stop MSSQLSERVER && net start MSSQLSERVER.

Step 3: Confirm the Drive or Directory Exists

  • If the error references a drive letter that no longer exists (e.g., after a storage migration), recreate the directory structure manually.
  • Use PowerShell to quickly check: Test-Path "D:\SQLData\".
  • If using a SAN or mounted volume, ensure it is online via Disk Management (diskmgmt.msc).

Step 4: Correct the CREATE DATABASE or ATTACH Statement

  • If attaching a database, rerun the command with the corrected file path:
  CREATE DATABASE YourDB
  ON (FILENAME = 'D:\SQLData\YourDB.mdf'),
     (FILENAME = 'D:\SQLData\YourDB_log.ldf')
  FOR ATTACH;
  • Ensure both the .mdf and .ldf paths are specified correctly and both files are present.

Step 5: Review SQL Server Error Log for Additional Clues

  • Open SQL Server Management Studio (SSMS) and navigate to Management > SQL Server Logs.
  • Look for accompanying errors (e.g., Error 5120 or 17204) that provide more specific detail on the root cause.
  • Address any secondary errors first, as they often reveal the true underlying issue (e.g., antivirus lock, disk I/O failure).

Alternative or Verification Steps

  • Run RESTORE VERIFYONLY FROM DISK = 'path_to_backup.bak' to confirm backup file integrity before attempting a restore.
  • If permissions and paths are correct but the error persists, try detaching and reattaching the database using sp_detach_db followed by a fresh CREATE DATABASE ... FOR ATTACH command.