Why This Error Happens
This message appears after executing an ALTER DATABASE ... MODIFY FILE statement to change the physical path of a database file in sys.master_files. SQL Server 2025 updates the system catalog immediately, but the actual file move/rename on disk is not performed automatically — the engine simply records the new path and waits for the next database restart or SQL Server service restart to use it. If the physical file isn’t manually relocated to the new path before that restart, or if the service account lacks permissions on the new directory, the database will fail to come back online.
Step-by-Step Resolution Guide
Step 1: Confirm the Catalog Change Was Intentional
- Run the following to see what SQL Server now expects as the file path:
SELECT name, physical_name FROM sys.master_files WHERE database_id = DB_ID('YourDatabaseName');
- Compare the
physical_namecolumn against the actual location of the.mdf/.ndf/.ldffile on disk. - If the path shown doesn’t match reality, you know the catalog update hasn’t been matched by a physical file move yet.
Step 2: Take the Database Offline and Move the Physical File
- In SQL Server Management Studio (SSMS) or via T-SQL, set the database offline:
ALTER DATABASE [YourDatabaseName] SET OFFLINE;
- Manually move/copy the file (using File Explorer or
Move-Itemin PowerShell) from its old location to the new path exactly as recorded insys.master_files. - Example PowerShell command:
Move-Item "D:\OldPath\YourDB.mdf" "E:\NewPath\YourDB.mdf"
Step 3: Grant Correct NTFS Permissions on the New Path
- Ensure the SQL Server service account (e.g.,
NT Service\MSSQLSERVERor a custom domain service account) has Full Control on the new folder. - Use
icaclsto verify/grant permissions:
icacls "E:\NewPath" /grant "NT SERVICE\MSSQLSERVER:(OI)(CI)F"
- Without this, SQL Server 2025 will throw an access-denied error when trying to reopen the file at startup.
Step 4: Bring the Database Back Online
- Set the database online again:
ALTER DATABASE [YourDatabaseName] SET ONLINE;
- Monitor the SQL Server Error Log (via SSMS > Management > SQL Server Logs, or
xp_readerrorlog) to confirm the file was found and mounted correctly at the new path.
Step 5: Restart the SQL Server Service (If Needed)
- If the database still won’t come online, restart the SQL Server service via SQL Server Configuration Manager or:
Restart-Service -Name 'MSSQLSERVER'
- This forces SQL Server to fully re-read
sys.master_filesand re-attach using the new physical path.
Alternative or Verification Steps
- Verify success by querying
sys.master_filesagain and confirming thestate_desccolumn showsONLINEfor all files tied to the database. - If the file move was skipped or done incorrectly, you can revert the catalog entry back to the original path (while the DB is offline) using another
ALTER DATABASE ... MODIFY FILEcommand pointing to the old, still-valid location, then retry the move process carefully.