SQL Server error 939 means the database engine cannot start a database because a file it needs is missing, inaccessible, or inconsistent with the metadata in the system catalog. The fix is to identify which file is blocking startup, restore or repair that file from a known-good backup, and only then bring the database online. Do not detach, drop, or force-attach the database until you have a verified backup of the current state.

What You'll Need

  • Administrative access to the SQL Server instance (sysadmin or equivalent).
  • A recent full backup of the affected database, plus any log backups needed to reach the desired recovery point.
  • The SQL Server error log and the Windows Application event log for the same time window.
  • Enough free disk space on the drive holding the database files and on the drive holding the backup files.
  • The SQL Server Configuration Manager and, if you will copy files, a login with file-system permissions on the data and log folders.

Step-by-Step

  1. Capture the exact error text. Open SQL Server Management Studio (SSMS), connect to the instance, and run SELECT * FROM sys.messages WHERE message_id = 939; to confirm the message wording for your version. Then read the current error log from Object Explorer under Management > SQL Server Logs, or open the file directly from the Log folder under the instance directory. The log entry for error 939 usually names the file or the reason (missing file, access denied, file size mismatch). Menu labels can differ slightly by SSMS version and by SQL Server version.
  2. Check the database state. Run SELECT name, state_desc, user_access_desc FROM sys.databases; and note whether the database shows RECOVERY_PENDING, SUSPECT, or OFFLINE. Also run SELECT name, physical_name, state_desc FROM sys.master_files WHERE database_id = DB_ID('YourDatabase'); to list every file the engine expects. Replace YourDatabase with the real name.
  3. Verify each file exists and is reachable. Using File Explorer or a command prompt on the server, confirm that every physical_name from the previous step exists at that exact path. Check that the SQL Server service account has read and write permission on the folder and the file, and that no antivirus or backup agent is holding a lock. If a file was moved, the metadata still points to the old path, which triggers error 939.
  4. Take a safety copy before changing anything. Copy the existing .mdf, .ndf, and .ldf files to a separate folder, or take a file-system snapshot if your platform supports it. This preserves the current state in case a repair attempt makes things worse.
  5. If the file is simply in the wrong place, point SQL Server at the new path. With the database offline, run ALTER DATABASE YourDatabase MODIFY FILE (NAME = logical_name, FILENAME = 'D:\NewPath\file.mdf'); for each moved file, then ALTER DATABASE YourDatabase SET ONLINE;. This works only when the file itself is intact and the only problem was the path.
  6. If the file is missing or corrupt, restore from backup. In SSMS, right-click Databases > Restore Database, choose the backup set, and restore with the WITH REPLACE option only after you have confirmed the backup is the right one. If the database will not come online at all, restore it under a temporary name first, verify the data, then drop and restore the original name. Restoring overwrites the current files, so the safety copy from step 4 matters.
  7. If you have no backup, try emergency repair options in order. First, set the database to EMERGENCY mode with ALTER DATABASE YourDatabase SET EMERGENCY;, then run DBCC CHECKDB (YourDatabase) WITH REPAIR_ALLOW_DATA_LOSS; only as a last resort. That option can delete data, so use it only when no backup exists and the data is otherwise unrecoverable. After repair, run DBCC CHECKDB again without repair options to confirm consistency, then set the database back to MULTI_USER.
  8. Bring the database online and verify. Run ALTER DATABASE YourDatabase SET ONLINE;, then SELECT name, state_desc FROM sys.databases WHERE name = 'YourDatabase'; to confirm it reads ONLINE. Run a quick DBCC CHECKDB (YourDatabase) WITH NO_INFOMSGS; and a test query against a known table.

Common Mistakes

  • Detaching or dropping the database before taking a file-system copy, which destroys the evidence you need for recovery.
  • Using REPAIR_ALLOW_DATA_LOSS as a first step instead of a last resort; it can remove rows and pages permanently.
  • Restoring over the live files without checking that the backup is the correct one and that the restore will not overwrite a database you still need.
  • Assuming error 939 is always corruption. In many cases the file is present but the service account lost permission after a password change or a drive remap.
  • Ignoring the Windows event log, which often shows the underlying cause (disk full, access denied, file locked) that the SQL error only summarises.

Tips

  • Record the logical file names from sys.master_files before any ALTER DATABASE MODIFY FILE statement; the logical name, not the physical path, is what the statement needs.
  • Keep the SQL Server service account out of the local Administrators group and give it explicit rights only on the data and log folders; this makes permission problems easier to spot.
  • Exclude database files and backup folders from real-time antivirus scanning where your security policy allows it, since file locks are a common cause of startup failures.
  • Test restores on a schedule so that the backup you rely on during an incident is one you have actually proven works.

Troubleshooting

If the database still will not start after the steps above, work through these checks in order. First, confirm the SQL Server service itself started cleanly and that no other database on the instance is also failing, which would point to an instance-level problem rather than one database. Second, re-read the error log for the newest entry after each attempt; the message often changes as each blocking file is resolved. Third, check disk space on every drive that holds a database file, including the log drive, because a full volume prevents startup. Fourth, verify the service account can open the file by testing with a simple copy operation under that account. If the file is on a network share, confirm the share is reachable and that the service account has rights there. If DBCC CHECKDB reports errors it cannot repair, restore from backup; do not keep running repair options repeatedly. If no backup exists and repair fails, contact Microsoft support or a data-recovery specialist before deleting anything.

Frequently Asked Questions

What does SQL Server error 939 actually mean?

It means the engine could not start the database because a required file is missing, inaccessible, or inconsistent with the system catalog. The exact cause is usually named in the SQL Server error log entry that accompanies the message.

Can I fix error 939 without a backup?

Sometimes. If the only problem is a moved file or a permission change, correcting the path or the rights is enough. If the file is corrupt and no backup exists, emergency-mode repair is the remaining option, and it can lose data.

Will restoring the database fix error 939?

A restore from a verified backup replaces the damaged or missing files and normally brings the database online. Confirm the backup is the correct one and that you are willing to overwrite the current state before you start.

Does error 939 affect other databases on the same instance?

Usually not. It is tied to the files of one database, so other databases typically stay online. If several databases fail together, look for an instance-level cause such as a full disk or a service account problem.

Is it safe to run DBCC CHECKDB with REPAIR_ALLOW_DATA_LOSS?

Only as a last resort when no backup exists. The option can delete data to make the database consistent, so take a file-system copy of the files first and accept that some rows may be lost.

How do I stop error 939 from coming back?

Keep tested backups, monitor disk space, keep the service account permissions stable, and avoid moving database files without updating the metadata with ALTER DATABASE MODIFY FILE.