SQL Server error 947 (“Error while closing database. Check for previous errors.”) means SQL Server could not close the database cleanly because an earlier error left it in an inconsistent state. The fix is to find and resolve that earlier error, not to force the database closed. Start by reading the SQL Server error log and the most recent entries in the Windows Application log for the database name, then address the underlying cause (usually a failed file operation, a permissions problem, or a transaction that could not complete). Once the earlier error is cleared, the close operation succeeds and the database returns to a normal state.

What You'll Need

  • Administrative access to the SQL Server instance (a login in the sysadmin role, or permission to view the error log and run DBCC commands).
  • Access to the SQL Server error log, either through SQL Server Management Studio (SSMS) or the file system.
  • Access to the Windows Event Viewer on the database server, specifically the Application log.
  • Enough free disk space on the drive that holds the database files and the log file.
  • A current backup of the affected database before you make any changes.

Step-by-Step

  1. Do not restart SQL Server yet. A restart can clear the symptom but also destroys the evidence you need. Capture the current state first.
  2. Open the SQL Server error log. In SSMS, connect to the instance, expand Management, right-click SQL Server Logs, and choose View for the current log. Alternatively, run EXEC sp_readerrorlog; in a query window. Look for entries mentioning the database name and the words “error”, “failed”, “I/O”, or “operating system”.
  3. Check the Windows Application log. Open Event Viewer on the server, expand Windows Logs, and select Application. Filter for the SQL Server source and the time window around the 947 error. Disk, permission, and antivirus errors often appear here but not in the SQL log.
  4. Identify the earlier error. The 947 message is a follow-on error. The real cause is the entry immediately before it that names a file, a drive, a permission, or a transaction. Write down the exact error number and message.
  5. Check disk space and file access. Confirm the drive holding the database files has free space, and that the SQL Server service account still has read and write permission to the data and log folders. A full disk or a changed folder permission is a common cause of a failed close.
  6. Check for long-running or blocking transactions. Run DBCC OPENTRAN; against the database to see whether an open transaction is preventing clean shutdown. Query sys.dm_exec_requests and sys.dm_tran_session_transactions to find the session responsible. Do not kill sessions blindly; confirm what the session is doing first.
  7. Fix the root cause. Free disk space, restore the correct service account permissions, resolve the blocking session through the application owner, or repair the file path if a file was moved. The specific fix depends on the earlier error you found in step 4.
  8. Retry the operation that triggered 947. If the error appeared during a restore, detach, or shutdown, repeat that operation now that the cause is resolved. If it appeared during a normal close, run ALTER DATABASE [YourDB] SET OFFLINE; and then ALTER DATABASE [YourDB] SET ONLINE; to confirm the database can transition cleanly.
  9. Run a consistency check. Execute DBCC CHECKDB ([YourDB]) WITH NO_INFOMSGS; to confirm the database is healthy after the incident. If it reports corruption, restore from the most recent known-good backup rather than attempting repairs on a production system.
  10. Document and monitor. Note the earlier error and the fix in your operations log. Watch the error log for a few days to confirm the 947 message does not return.

Common Mistakes

  • Restarting the SQL Server service first. This clears the message but loses the diagnostic trail, and the underlying problem usually returns.
  • Treating 947 as the root error. It is a secondary message. Fixing it directly is not possible; you must fix the earlier error it points to.
  • Killing sessions without checking. Terminating the wrong session can roll back a large transaction and extend the outage.
  • Ignoring the Windows Event log. Many file-level and permission errors appear only there, not in the SQL Server log.
  • Skipping the backup. Any change to database state, including detach and restore, should be preceded by a verified backup.

Tips

  • Use sp_readerrorlog with a search string to filter the log quickly, for example EXEC sp_readerrorlog 0, 1, N'YourDB';.
  • Check the SQL Server error log for the entries immediately before the 947 message; that is where the real cause sits.
  • If the database is in a restoring or recovery state, wait for recovery to finish before running further commands.
  • Keep the SQL Server service account permissions stable; avoid changing folder ownership on data and log directories.
  • Schedule consistency checks and backups so that a failed close is caught early rather than during an outage.

Troubleshooting

If the 947 error persists after you have addressed the earlier error, work through these checks in order:

  1. Confirm the database state. Run SELECT name, state_desc FROM sys.databases WHERE name = 'YourDB';. If it shows RECOVERY_PENDING or SUSPECT, the file-level problem is still present.
  2. Re-check permissions. Confirm the SQL Server service account has full control on the data and log folders, and that no antivirus product is locking the files. Add exclusions for SQL Server data and log directories according to your security policy.
  3. Check for pending file operations. If a file was moved or deleted outside SQL Server, restore it to its original path or use ALTER DATABASE ... MODIFY FILE to point to the new location, then retry.
  4. Review the Windows Event log again. New errors after your fix often point to a second cause that was masked by the first.
  5. If the database remains suspect, restore from the most recent verified backup. Do not attempt emergency repairs on a production database without a backup and a maintenance window.

Frequently Asked Questions

What does SQL Server error 947 actually mean?

It means SQL Server could not close the database because an earlier error left it in an inconsistent state. The 947 message is a follow-on; the real cause is the error logged before it.

Can I fix 947 by restarting SQL Server?

Restarting may clear the message temporarily, but it also removes the diagnostic evidence and the underlying problem usually returns. Capture the logs first, then fix the earlier error.

Where do I find the earlier error?

In the SQL Server error log (Management > SQL Server Logs in SSMS, or sp_readerrorlog) and in the Windows Event Viewer Application log. Look at the entries immediately before the 947 message.

Is 947 caused by disk space or permissions?

Often, yes. A full disk, a changed service account permission, or an antivirus lock on the data or log files are common causes. Check both before making other changes.

Will I lose data when fixing 947?

Not if you follow the steps and take a backup first. Avoid detaching or restoring without a verified backup; those operations can lose recent changes if something goes wrong.

How do I confirm the database is healthy afterward?

Run DBCC CHECKDB on the database and confirm it returns no errors. Also check that the database state is ONLINE in sys.databases.