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

Troubleshooting Guide: SQL Server Error 5057 – “Cannot Add File”

Why This Error Happens

Error 5057 typically occurs when SQL Server attempts to add a file to a filegroup or database but encounters a conflict, such as a duplicate logical file name, an invalid or inaccessible file path, or insufficient NTFS permissions on the target directory. This can also happen if the filegroup specified does not exist, is marked read-only, or if the database is in a state (such as SINGLE_USER or RESTORING) that prevents file modifications. Corrupted system catalog entries in sys.master_files can also trigger this error during file addition operations.

Step-by-Step Resolution Guide

Step 1: Verify File and Filegroup Names

  • Run SELECT name, physical_name FROM sys.master_files WHERE database_id = DB_ID('YourDatabaseName'); to check for existing duplicate logical names.
  • Ensure the filegroup you’re targeting actually exists using SELECT name FROM sys.filegroups;.
  • Confirm you are not reusing a logical file name already assigned to another file in the instance.

Step 2: Check File System Permissions and Path Validity

  • Navigate to the target directory (e.g., C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\DATA\) and confirm it exists.
  • Right-click the folder, go to Properties > Security, and ensure the SQL Server service account (e.g., NT Service\MSSQLSERVER) has Full Control.
  • If the path is on a mapped network drive or UNC path, confirm SQL Server has permission to write there — UNC paths often require additional trust configuration in Server Properties > Advanced.

Step 3: Confirm Database State and Compatibility Level

  • Run SELECT state_desc FROM sys.databases WHERE name = 'YourDatabaseName'; to ensure the database is ONLINE.
  • If the database is in SINGLE_USER mode, switch it to MULTI_USER using ALTER DATABASE YourDatabaseName SET MULTI_USER;.
  • Verify the database is not flagged as READ_ONLY by running ALTER DATABASE YourDatabaseName SET READ_WRITE; if needed.

Step 4: Retry the ALTER DATABASE Command

  • Use a corrected and unique logical file name and physical path:
  ALTER DATABASE YourDatabaseName 
  ADD FILE (NAME = 'YourDB_Data2', FILENAME = 'C:\SQLData\YourDB_Data2.ndf') 
  TO FILEGROUP [PRIMARY];
  • Double-check drive space availability on the target volume before executing.

Alternative or Verification Steps

  • After running the ALTER DATABASE command successfully, verify the new file was added by querying sys.master_files or checking SSMS > Database Properties > Files.
  • If the issue persists, restart the SQL Server service via services.msc or PowerShell (Restart-Service MSSQLSERVER) to clear any cached metadata locks, then retry the operation.