Error 954 means SQL Server cannot open the database because the underlying database file is missing, offline, or inaccessible. The full message usually reads "The database cannot be opened. It is in the middle of a restore." or "The database cannot be opened. It is offline." The fix depends on which state the database is actually in, so the first step is to read the complete error text and confirm the database's current state with a query before changing anything.

What You'll Need

  • SQL Server Management Studio (SSMS) or Azure Data Studio connected to the instance, with at least db_owner rights on the database or sysadmin on the instance.
  • The full error message text, including any state number, from the SQL Server error log or the client application.
  • Access to the server's file system if the error points to a missing or inaccessible file.
  • A current backup of the database before making structural changes.

Step-by-Step

  1. Read the full error. Error 954 is a general "cannot be opened" message; the sentence after it tells you the real cause. Look in SSMS under Object Explorer > Management > SQL Server Logs, or query the error log with EXEC sp_readerrorlog;. Note whether it says the database is in restore, offline, suspect, or that the file is missing.
  2. Check the database state. Run SELECT name, state_desc, user_access_desc FROM sys.databases WHERE name = 'YourDatabase';. The state_desc column will show ONLINE, OFFLINE, RESTORING, RECOVERING, SUSPECT, or EMERGENCY. This determines the next step.
  3. If the state is RESTORING: a restore was started but not completed. If you have the backup, finish the restore with RESTORE DATABASE YourDatabase WITH RECOVERY;. If you do not have the backup and the database was never meant to be restored, confirm with the person who ran the restore before issuing any command, because WITH RECOVERY finalizes the database and cannot be undone.
  4. If the state is OFFLINE: bring it online with ALTER DATABASE YourDatabase SET ONLINE;. If this fails, the error returned will name the missing file or permission problem; go to step 6.
  5. If the state is SUSPECT or RECOVERY_PENDING: do not run repairs yet. Take a file copy or backup of the MDF and LDF first, then try ALTER DATABASE YourDatabase SET EMERGENCY; followed by DBCC CHECKDB (YourDatabase); to see what is wrong. Only run repair options after you have a backup and have read the CHECKDB output.
  6. If the error names a file: open the error log line and note the exact path. Confirm the file exists on disk, that the SQL Server service account has read and write permission to the folder, and that the path matches SELECT name, physical_name FROM sys.master_files WHERE database_id = DB_ID('YourDatabase');. A moved or renamed file is a common cause after a server migration.
  7. If the file was moved: take the database offline, correct the path with ALTER DATABASE YourDatabase MODIFY FILE (NAME = logical_name, FILENAME = 'new_path');, then bring it online. Use the logical file names from sys.master_files, not the physical file names.
  8. If the database is a log shipping or availability group secondary: error 954 is expected while the database is in RESTORING or recovering. Do not force it online; check the log shipping or availability group health instead.
  9. Restart the SQL Server service only after the above checks. A service restart clears some transient states but will not fix a missing file or an incomplete restore. Warn users first, because the restart disconnects everyone.
  10. Verify. Run SELECT name, state_desc FROM sys.databases WHERE name = 'YourDatabase'; again and confirm ONLINE, then run a simple SELECT TOP 10 * FROM dbo.SomeTable; to confirm the database is readable.

Common Mistakes

  • Running RESTORE ... WITH RECOVERY on a database that is intentionally in RESTORING as a log shipping secondary, which breaks the log shipping chain.
  • Using physical file names in MODIFY FILE instead of the logical names shown in sys.master_files.
  • Taking the database offline or detaching it without a backup first.
  • Assuming error 954 always means corruption; it usually means state or file access, not damaged pages.
  • Ignoring the state number in the error text, which often points to the exact cause.

Tips

  • Always capture the full error log entry before changing anything; the message after "It is" is the key clue.
  • Keep a copy of the MDF and LDF files before running any repair command.
  • Use sys.databases and sys.master_files rather than guessing paths from Object Explorer.
  • If the database is part of an availability group, check the availability group dashboard before touching the database state.
  • Document the file paths and service account permissions for each database so a move or migration is easier to diagnose next time.

Troubleshooting

If the database will not come online after ALTER DATABASE ... SET ONLINE, read the new error message; it usually names the file or permission that is blocking it. If CHECKDB reports consistency errors, restore from a known-good backup rather than running repair immediately, because repair can remove data. If the error persists after the file path and permissions are correct, check whether the SQL Server service account changed, whether antivirus is locking the file, and whether the disk holding the file is full or offline. For a database stuck in RECOVERY_PENDING, confirm the file exists and is not read-only, then retry the online command. If none of this resolves it, open a support case with Microsoft or your database vendor and include the full error log, the output of the sys.databases and sys.master_files queries, and a description of any recent restore, move, or failover.

Frequently Asked Questions

What does SQL Server error 954 actually mean?

It means SQL Server could not open the database file. The sentence after the error usually says the database is in the middle of a restore, offline, or that a file is missing or inaccessible.

Can I fix error 954 without a backup?

Sometimes, if the cause is an offline state or a moved file, yes. If the cause is corruption or an incomplete restore, a backup is the safe route. Take a file copy before any repair attempt.

Does restarting SQL Server fix error 954?

Only for transient states. A restart does not fix a missing file, wrong path, or incomplete restore, and it disconnects all users, so check the database state first.

Why does error 954 appear on a log shipping secondary?

A secondary database is intentionally in RESTORING or standby state, so it cannot be opened for normal use. That is expected; check log shipping health instead of forcing it online.

What is the difference between RESTORING and RECOVERY_PENDING?

RESTORING means a restore is in progress or waiting for the next log. RECOVERY_PENDING means SQL Server cannot start recovery, often because a file is missing or inaccessible.

Will ALTER DATABASE SET ONLINE lose data?

No, bringing an offline database online does not delete data. It only changes the state. Still take a backup first if the database has been offline for a long time.