SQL Server Error 926 occurs when the database engine cannot open a database because it has been placed in a state that prevents normal access, typically due to corruption, a failed recovery process, or the database being marked as suspect. To resolve this, you must force the database into EMERGENCY mode, set it to SINGLE_USER mode, and then run the DBCC CHECKDB command with the REPAIR_ALLOW_DATA_LOSS option to fix structural inconsistencies. This process recovers the database by removing corrupt pages, though it may result in the loss of some data that cannot be salvaged.
What You'll Need
- SQL Server Management Studio (SSMS) installed and configured.
- Sysadmin or server-level administrative permissions to execute database state changes.
- A full backup of the database (if available) to compare data after the repair process.
- Access to the server's file system to verify that .mdf and .ldf files are not locked by other processes.
Step-by-Step
- Identify the Affected Database: Open SQL Server Management Studio (SSMS) and connect to your instance. Look at the Object Explorer. The database triggering Error 926 will often be listed as (Suspect) or (Recovery Pending) next to its name. If it is not visible, run
SELECT name, state_desc FROM sys.databasesin a new query window to confirm the current state of all databases. - Switch to EMERGENCY Mode: Because the database cannot be opened normally, you must put it into EMERGENCY mode. This mode makes the database read-only and allows the administrator to access the database even if it is marked as suspect. Execute the following command:
ALTER DATABASE [YourDatabaseName] SET EMERGENCY;
Replace[YourDatabaseName]with the actual name of your database. - Set to SINGLE_USER Mode: To perform repair operations, SQL Server requires exclusive access to the database files. This prevents other users or background processes from interfering with the repair. Execute the following command:
ALTER DATABASE [YourDatabaseName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
TheROLLBACK IMMEDIATEclause is critical because it terminates any existing connections to the database, ensuring the state change happens instantly. - Run the Integrity Check: Before attempting a repair, it is useful to know the extent of the damage. Run a check to identify the specific errors causing Error 926:
DBCC CHECKDB ([YourDatabaseName]);
Review the messages in the results pane. Look for errors related to page corruption, allocation errors, or consistency failures. - Execute the Repair Command: Since Error 926 usually implies a failure that prevents the database from starting, the standard repair options often fail. You must use the most aggressive repair level. Execute the following command:
DBCC CHECKDB ([YourDatabaseName], REPAIR_ALLOW_DATA_LOSS);
Warning: As the name suggests, this command may delete corrupt data pages to make the database structurally sound again. This is a last-resort action when no healthy backup exists. - Return to MULTI_USER Mode: Once the repair process completes and the messages indicate that the database is now consistent, you must allow other users and applications to connect again. Execute the following command:
ALTER DATABASE [YourDatabaseName] SET MULTI_USER; - Verify Database Status: Right-click the database in Object Explorer and select Refresh. The (Suspect) or (Recovery Pending) label should be gone. Try to expand the Tables folder to ensure the database is fully accessible.
Common Mistakes
One of the most frequent mistakes is attempting to run DBCC CHECKDB without first setting the database to EMERGENCY and SINGLE_USER mode. If the database is in a suspect state, the command will simply fail because the engine cannot open the database files. Users often try to restart the SQL Server service multiple times, hoping the database will recover on its own; however, if the transaction log is corrupted or a critical system page is missing, a restart will not fix the underlying structural issue.
Another common error is forgetting the ROLLBACK IMMEDIATE clause when switching to SINGLE_USER mode. If a background process (like a monitoring tool or a lingering application connection) is holding a lock on the database, the ALTER DATABASE command will hang indefinitely, leaving the administrator wondering why the database won't switch modes. Finally, some users attempt to delete the log file (.ldf) manually from the Windows folder to "reset" the database. This is dangerous and can lead to permanent data loss or a database that cannot be attached at all.
Tips
To prevent Error 926 from recurring, implement a strict backup strategy. This should include full daily backups, differential backups every few hours, and transaction log backups every 15 minutes. If you have a healthy backup, it is always safer to restore the backup than to use REPAIR_ALLOW_DATA_LOSS, as the repair command provides no guarantee on which specific rows or tables will be deleted to fix the corruption.
Regularly schedule DBCC CHECKDB to run as part of your maintenance plan. Corruption often happens silently due to hardware failure or I/O subsystem issues. By running integrity checks weekly or monthly, you can catch corruption while it is small and manageable, rather than waiting for the database to crash and trigger Error 926. Additionally, ensure your server is using a stable power supply (UPS) and that the storage drives are monitored for SMART errors, as disk failure is the primary cause of this specific error code.
Troubleshooting
If the ALTER DATABASE [YourDatabaseName] SET EMERGENCY; command fails, it usually means the SQL Server service does not have sufficient permissions to access the underlying .mdf or .ldf files. Check the Windows folder permissions for the directory where the database files are stored. Ensure the account running the SQL Server service (e.g., NT Service").
If DBCC CHECKDB with REPAIR_ALLOW_DATA_LOSS finishes but the database still shows as Suspect, check the SQL Server Error Log (found under Management > SQL Server Logs in SSMS). Look for entries mentioning "Operating system error" or "Access is denied." This often indicates that the disk is physically failing or that an antivirus program is locking the database files during the repair process. Try disabling antivirus scanning for the SQL Server data folders temporarily.
In cases where the database cannot even be put into EMERGENCY mode, you may need to perform a "detach and attach" operation. Detach the database, move the files to a new location, and attempt to attach them using the FOR ATTACH_REBUILD_LOG clause. This forces SQL Server to create a new transaction log, which can bypass errors caused by a corrupted log file that prevents the database from opening.
Frequently Asked Questions
Will REPAIR_ALLOW_DATA_LOSS delete my entire database?
No, it will not delete the entire database. It only deletes the specific pages or records that are so corrupted they cannot be repaired. However, you cannot predict which specific data will be lost; it could be a few rows in a minor table or a significant chunk of a primary table.
Can I fix Error 926 without losing data?
The only way to guarantee zero data loss is to restore the database from a known healthy backup. If you do not have a backup, REPAIR_ALLOW_DATA_LOSS is the only built-in tool available, and it carries a risk of data deletion.
Why did my database suddenly become suspect?
The most common causes include unexpected server shutdowns (power loss), failing hard drives, network interruptions during a remote file access, or bugs in the storage controller driver that cause "torn pages" during write operations.
How long does the repair process take?
The duration depends entirely on the size of the database and the speed of your disk I/O. For small databases, it may take seconds; for multi-terabyte databases, it can take several hours. Monitor the progress via the messages tab in SSMS.
Is it safe to run these commands on a production server?
These commands should be used with extreme caution. Because REPAIR_ALLOW_DATA_LOSS can modify data, you should always attempt to copy the .mdf and .ldf files to a separate drive as a "manual backup" before running the repair, so you have a point to return to if the repair makes things worse.