state_desc in sys.databases, then find the error log line that names the file. 945 almost always means the database is RECOVERY_PENDING because SQL Server cannot open one of its files. Fix the path or the access, run ALTER DATABASE ... SET ONLINE, and it comes back untouched. If the file is really gone, restore before you repair.945 is a symptom, not the disease. Something stopped SQL Server opening one of the database’s files at startup, the database parked itself, and every connection that tries to use it gets this message instead. The three causes it names sit in strict order of likelihood: inaccessible files first by a distance, then disk space, then memory.

What the Instance Actually Looks Like
Two queries tell you nearly everything. The first is the state of the database, and with 945 it will almost certainly read RECOVERY_PENDING: SQL Server knows the database exists, cannot open its files, and has not even been able to begin recovery.
SELECT name, state_desc, user_access_desc
FROM sys.databases
WHERE name = 'YourDb';
The second is where SQL Server believes the files are, which you then check against the disk by hand:
SELECT type_desc, state_desc, physical_name
FROM sys.master_files
WHERE database_id = DB_ID('YourDb');

sys.master_files still says ONLINE for both files, even with the log pointing at a file that is not there, so it will not tell you which one is the problem.
The error log fills in whichever detail the message left out. When I broke a database for this post by pointing it at a file that does not exist, the log carried one line that names the file and the operating system error: FCB::Open failed: Could not open file ... for file number 1. OS error: 2(The system cannot find the file specified.). The 5120 unable to open the physical file and 5181 could not restart the database messages went back to the session that ran the SET ONLINE, not into the log. The 945 you see in your session is the public face of that chain. A missing log file leaves a different line, so search for both:
EXEC xp_readerrorlog 0, 1, N'FCB::Open failed'; -- a data file
EXEC xp_readerrorlog 0, 1, N'Operating system error', N'YourDb'; -- a log file
With the log file pointed at a path that does not exist, every attempt to start the database logged the same line:

FileMgr::StartLogFiles means a log file; a data file shows up as FCB::Open failed. Either way the number in brackets is the operating system error, and it maps to a cause in the table below. The session that ran the SET ONLINE got the short version:

MS Docs covers MSSQLSERVER_945 and database states in full.
The Usual Suspects, In Order
| Cause | OS error in the log | How it happens |
|---|---|---|
| The file moved or was renamed | 2, file not found | A drive letter changed, a file was tidied into a new folder, a SAN volume came back under a different path, or a migration moved files without updating the database. SQL Server still holds the old path in sys.master_files and cannot know where the file went. |
| The engine lost permission | 5, access denied | The file is exactly where it should be, but an ACL change, a restore from backup software, or a copy between machines stripped the SQL Server service account’s rights to it. You can see the file in Explorer; the service cannot open it. Error 5120 covers the permissions in detail. |
| The volume is not there yet | 3, path not found | After a reboot, SQL Server can start before a mount point, iSCSI target or BitLocker-protected volume is available. Databases on that volume come up RECOVERY_PENDING and 945 until it appears. Error 5123 is the same problem when SQL Server creates a file. |
| Another process holds the file | 32, file in use | Usually antivirus, a file-level backup agent, or a second instance pointed at the same file. Stop that process or exclude the database folders. |
| Disk full or out of memory | 112, disk full | The two causes the message names last, and the two you will meet least. The error log makes it obvious when either is genuinely the reason. For a full disk, Disk Is Full or the Log Will Not Truncate is the next page. |
Only OS error 2 was reproduced as a RECOVERY_PENDING startup for this post; error 5 was captured on the attach shown further down. The other numbers are documented, not reproduced here. No operating system error at all, but a database that got as far as recovery and stopped, is a different state: In Recovery if it is still working through the log, SUSPECT (Error 926) if recovery ran and failed.
The Fix, Measured
Once the file problem is solved, the database does not need restoring, rebuilding or detaching. It needs to be told to start again. In the reproduction for this post the repair was two statements: point the catalog back at the right file, then bring the database online.
-- Only needed if the path in sys.master_files is wrong:
ALTER DATABASE YourDb
MODIFY FILE (NAME = YourDb, FILENAME = 'D:\SQLData\YourDb.mdf');
ALTER DATABASE YourDb SET ONLINE;
If the path was right and the problem was access or an absent volume, fix that side instead: restore the service account’s rights on the folder, or bring the volume back, and then run the SET ONLINE. The database went from RECOVERY_PENDING to ONLINE the moment the file could be opened, with no recovery drama, because nothing about the data ever went wrong.
The missing log file case is the same fix. Pointing the log back at its real path and running the SET ONLINE was the whole repair:

All 1,000 rows were there, the recovery model was still FULL, and the backup chain was untouched.
When the Log File Is Really Gone
If the drive died and the .ldf is not coming back, the order is restore, then rebuild, then repair.
- Restore from backup. The last full plus the log backups gets you a transactionally consistent database. Without the log file you cannot take a tail-log backup, so anything after the last log backup is lost either way; restore is still the clean option. Get Backup Coverage tells you what you have.
- Rebuild the log on attach, only after a clean shutdown.
CREATE DATABASE ... FOR ATTACH_REBUILD_LOGbuilds a new log when the database was shut down cleanly. Documented, not reproduced here: the attempt on the lab failed for a reason worth knowing, shown below. - Repair as the last resort. EMERGENCY mode plus
REPAIR_ALLOW_DATA_LOSS, with its cost in the next section.
To try the attach route, the database was taken offline and dropped first (dropping an offline database leaves its files on disk). The attach then failed with access denied. SQL Server sets file permissions when a database is detached or attached, and dropping the offline database reset them here too:

The service account could no longer open the .mdf. Getting it back needs a local administrator to reset the ACL. That is the strongest argument against the vendor advice to “detach and re-attach to rebuild the log”: you remove the database from the instance and can lose the ability to put it back. MS Docs covers this under Database detach and attach.
Repair Is the Last Resort, and This Is What It Costs
Before any of this, copy the .mdf and any surviving .ndf files somewhere safe, so a failed repair can be retried or handed to someone else. Then, on the lab database with its log file missing:
ALTER DATABASE YourDb SET EMERGENCY;
-- read-only, sysadmin only: copy out what you need now
ALTER DATABASE YourDb SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DBCC CHECKDB (YourDb, REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS;
ALTER DATABASE YourDb SET MULTI_USER;

The Messages tab carries the part that matters, the warning that the log was rebuilt:

Read what that cost, even on a database that lost no rows:
- The backup chain is gone. No log backup taken before the repair can be applied after it. Take a full backup straight away.
- The recovery model changed. It went in as FULL and came out as SIMPLE. Set it back, then take that full backup, or your log backup jobs will start failing.
- Consistency is not guaranteed. The lab database was shut down cleanly before the log went, so all 1,000 rows survived. After a crash, the log held work that recovery would have redone or undone; the rebuild throws it away and can leave half-finished changes in the data. Documented, not reproduced here.
- The application is now the check. CHECKDB proves the pages are readable, not that the business data is right. DBCC CHECKDB Found Corruption covers what to do with its output.
Note that EMERGENCY mode already let a sysadmin read all 1,000 rows. If restore is not possible, copying the data out in EMERGENCY mode into a new database is often a better outcome than repairing in place. MS Docs: DBCC CHECKDB.
What Not To Do
- Do not run repair first. In the most common cases (a moved file, a late volume, a permission) the fix is one
SET ONLINEand repair would have broken the backup chain for nothing. - Do not detach or drop the database to “reset” it. Detaching a database that cannot be opened throws away the catalog entry that tells you which file is missing, and a database that will not attach is a harder problem than a database that will not open. The lab attach above failed with OS error 5 after exactly that.
- Do not restart the service as a first move. If the file is still inaccessible, you get the same state back plus an outage for every other database. Restarting only helps when the real cause was a volume that has since come back.
- Do not reach for RESTORE yet. Restoring over a database whose files are merely mispointed converts a two-statement fix into a recovery exercise. Prove the files are actually gone or damaged first; the 823/824 family is the signal for damage, 945 on its own is not.
- Do not delete a log file because it looks spare. Check
sys.master_filesfor every file the database owns before touching the folder.
Frequently Asked Questions
Is RECOVERY_PENDING the same as SUSPECT?
The message mentions memory and disk space, but my disk is fine. Why say it?
Why does my error say Level 14 when the catalog says severity 16?
sys.messages at severity 16, and the engine raises it at Level 14 when a session hits it. Measured on SQL Server 2025 while writing this post.Can this happen to tempdb or master?
Can I read the data while it is RECOVERY_PENDING?
Why did my recovery model change to SIMPLE after the repair?
recovery_model_desc in sys.databases afterwards, set it back if it changed, and take a full backup to start a new chain.Where To Go Next
945 is the message; the neighbours are the states and the checks around it:
- Backup Failed or the Restore Is Stuck, how the database states after a restore tell apart from each other.
- Get Database Health, the state check that surfaces RECOVERY_PENDING across every database at once.
- Get Database File Details, every physical path the instance believes in, ready to compare against the disk.
- Get Recent Error Log Entries, the fastest way to the FCB::Open or StartLogFiles line behind a 945.
Leave a Reply