SQL Server error 927 means the database cannot be opened because it is in an inconsistent state, usually because a restore or recovery was interrupted, the database was detached improperly, or the underlying files are missing or damaged. The fastest fix is to check the SQL Server error log for the exact reason, then either bring the database online if it is only marked as restoring, or restore from a known-good backup if the files are corrupt. Do not run repair commands until you have a backup.

What You'll Need

  • Administrative access to the SQL Server instance (sysadmin or db_owner role).
  • SQL Server Management Studio (SSMS) or Azure Data Studio, or the sqlcmd utility.
  • A recent full backup of the affected database, plus any differential and transaction log backups taken after it.
  • The SQL Server error log, which records the exact cause of the 927 state.
  • Enough free disk space on the drive holding the database files and the log file.

Step-by-Step

  1. Read the actual error message. Error 927 is often accompanied by a more specific message such as "The log cannot be rebuilt because there were open transactions/users when the database was shutdown" or "The file cannot be opened." Open SSMS, connect to the instance, and run SELECT * FROM sys.master_files WHERE database_id = DB_ID('YourDatabase'); to confirm the physical file paths. Then open the error log via Object Explorer > Management > SQL Server Logs, or run EXEC sp_readerrorlog;. The newest entries at the top usually name the failing file or the reason recovery stopped.
  2. Confirm the database state. Run SELECT name, state_desc FROM sys.databases WHERE name = 'YourDatabase';. If the state is RESTORING, the database is waiting for a restore or log recovery to finish. If it is RECOVERY_PENDING, SQL Server cannot access the files. If it is SUSPECT, the files are likely damaged or inaccessible.
  3. Check file permissions and existence. On the SQL Server host, verify that the .mdf and .ldf files listed in step 1 exist at those exact paths. The SQL Server service account (for example, NT Service\MSSQLSERVER) must have full control on the folder and files. A common cause is a database file copied from another server without adjusting permissions, or a drive letter that changed after a reboot.
  4. If the state is RESTORING, finish the restore. Run RESTORE DATABASE YourDatabase WITH RECOVERY; to roll forward the log and bring the database online. Only do this if you are certain no further log backups need to be applied. If the restore was interrupted, re-run the original RESTORE statement with the correct WITH NORECOVERY or WITH RECOVERY option.
  5. If the log file is missing or damaged, rebuild it only as a last resort. First take a copy of the .mdf file. Then run ALTER DATABASE YourDatabase SET EMERGENCY;, ALTER DATABASE YourDatabase SET SINGLE_USER;, and DBCC CHECKDB ('YourDatabase', REPAIR_ALLOW_DATA_LOSS);. This can discard uncommitted transactions and may lose data. Afterward, run ALTER DATABASE YourDatabase SET MULTI_USER;. If the repair fails, restore from backup instead.
  6. Restore from backup if repair is not possible. Use RESTORE DATABASE YourDatabase FROM DISK = 'C:\Backups\YourDatabase.bak' WITH REPLACE, RECOVERY;. If you have differential or log backups, apply them in order with NORECOVERY on each intermediate restore and RECOVERY on the final one. Verify the restored database with DBCC CHECKDB ('YourDatabase'); before returning it to production.
  7. Prevent recurrence. After recovery, check that autogrow is enabled and the disk has free space, verify that backups complete on schedule, and avoid detaching databases while users are connected. If the server was shut down abruptly, review the Windows event log for disk errors.

Common Mistakes

  • Running DBCC CHECKDB ... REPAIR_ALLOW_DATA_LOSS before taking a file copy or backup. The repair can delete pages and make a later restore impossible.
  • Assuming error 927 always means corruption. In many cases the database is simply mid-restore or the service account lost permission to the folder.
  • Detaching and reattaching the database without first checking the error log. Reattaching a database with a missing log file produces the same 927 state.
  • Restoring over the live database without WITH REPLACE, which fails silently or leaves the database in RESTORING.
  • Ignoring disk space. A full drive prevents the log from growing and can leave the database in recovery pending.

Tips

  • Always capture the full error text and the relevant error log lines before changing anything; they tell you which fix applies.
  • Use WITH NORECOVERY for every restore except the final one, then finish with WITH RECOVERY.
  • Test restores on a separate instance before touching production.
  • Keep the SQL Server service account permissions documented so a server migration does not break file access.
  • Run DBCC CHECKDB on a schedule to catch corruption early, when backups are still usable.

Troubleshooting

If RESTORE ... WITH RECOVERY fails, read the message: "The log cannot be rebuilt" usually means the log file is missing or the database was not cleanly shut down. In that case, restore from the last full backup and apply log backups. If DBCC CHECKDB reports errors that repair cannot fix, restore from backup; do not keep running repair. If the database remains SUSPECT after a repair attempt, take the database offline with ALTER DATABASE YourDatabase SET OFFLINE;, copy the files aside, and restore. If permissions are the issue, grant the service account full control on the data folder and restart the SQL Server service. If the drive is full, free space or move the files, then retry recovery. When none of this works, contact Microsoft support with the error log and the output of DBCC CHECKDB.

Frequently Asked Questions

What does SQL Server error 927 actually mean?

It means SQL Server cannot open the database because it is in an inconsistent state, typically because recovery did not complete, the database is still restoring, or the files are inaccessible or damaged.

Can I fix error 927 without a backup?

Sometimes. If the database is only in RESTORING state, RESTORE ... WITH RECOVERY brings it online without a backup. If files are corrupt, repair may work but can lose data; a backup is the safe route.

Will repairing the database lose data?

REPAIR_ALLOW_DATA_LOSS can delete damaged pages and uncommitted transactions. That is why you copy the files and take a backup first.

Why does the database show RESTORING after a restore?

The restore was run with WITH NORECOVERY or was interrupted. Finish it with RESTORE DATABASE ... WITH RECOVERY; once all log backups are applied.

Can a missing log file cause error 927?

Yes. If the .ldf file is missing or inaccessible, SQL Server cannot recover the database and reports it as inconsistent. Restore from backup or rebuild the log only as a last resort.

How do I stop this from happening again?

Keep regular verified backups, monitor disk space, grant the service account correct folder permissions, and avoid detaching databases while users are connected.