How to fix Error 7901 on Windows Server 2025 / Windows 11

Troubleshooting Guide: Error 7901 – Repair Not Supported in Emergency Mode

Why This Error Happens

Error 7901 occurs because DBCC CHECKDB with a repair level of REPAIR_ALLOW_DATA_LOSS or REPAIR_REBUILD cannot be executed while a database is set to EMERGENCY mode. SQL Server 2025 restricts deep repair operations in this mode because the database is already in a read-only, minimally logged state used primarily for data extraction, not structural repair. The underlying cause is typically a corrupted system catalog, damaged transaction log, or a suspect database that was forced into emergency mode to allow limited read access, but the engine blocks repair commands to prevent further integrity damage during an unstable state.

Step-by-Step Resolution Guide

Step 1: Verify the Current Database State

  • Open SQL Server Management Studio (SSMS) or Azure Data Studio connected to your SQL Server 2025 instance.
  • Run the following query to confirm the database status:
  SELECT name, state_desc FROM sys.databases WHERE name = 'YourDatabaseName';
  • Confirm the state_desc returns EMERGENCY. If it returns SUSPECT, you must first transition it to EMERGENCY mode manually.

Step 2: Set the Database to SINGLE_USER Mode

  • Emergency mode repairs require exclusive access; multi-user connections will block the repair process.
  • Execute:
  ALTER DATABASE YourDatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
  • Ensure no other application pools, services, or SSMS tabs are holding active connections to the database.

Step 3: Take the Database Out of Emergency Mode Before Repair

  • Instead of repairing directly in EMERGENCY mode, revert it to a standard offline/restoring state first:
  ALTER DATABASE YourDatabaseName SET EMERGENCY;
  ALTER DATABASE YourDatabaseName SET SINGLE_USER;
  DBCC CHECKDB (YourDatabaseName, REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS;
  • On Windows Server 2025, ensure the SQL Server service account has full read/write permissions on the .mdf and .ldf file paths (typically under C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\DATA\).
  • If the log file is corrupted beyond repair, you may need to rebuild it using DBCC CHECKDB with REPAIR_REBUILD only after the database is out of strict emergency read-only state.

Step 4: Run the Repair Command Properly

  • Once the database is in SINGLE_USER mode (not purely EMERGENCY), execute:
  DBCC CHECKDB ('YourDatabaseName', REPAIR_ALLOW_DATA_LOSS);
  • Monitor the SQL Server Error Log located at C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG for real-time repair progress and any secondary corruption errors.

Step 5: Restore Multi-User Access

  • After the repair completes successfully, revert the database back to normal operation:
  ALTER DATABASE YourDatabaseName SET MULTI_USER;
  • Confirm the application or service connecting to the database can now read/write data without triggering Error 7901 again.

Alternative or Verification Steps

  • Run DBCC CHECKDB (YourDatabaseName) WITH NO_INFOMSGS, ALL_ERRORMSGS; after the fix to confirm zero allocation or consistency errors remain.
  • If corruption persists or the error reoccurs, the most reliable alternative is restoring the database from the last known good backup using RESTORE DATABASE YourDatabaseName FROM DISK = 'BackupPath.bak' WITH RECOVERY, as repair operations with data loss do not guarantee full referential integrity.