Troubleshooting Guide: Error 2596 – Repair Statement Not Processed (Database Cannot Be in Read-Only Mode)
Why This Error Happens
This error occurs when DBCC CHECKDB with a repair option (such as REPAIR_ALLOW_DATA_LOSS or REPAIR_REBUILD) is executed against a database that is currently set to READ_ONLY. SQL Server requires write access to the database files to perform repair operations, since the repair process must modify system and data pages to resolve corruption. This state is often inherited from a database that was manually set to read-only, restored in a read-only configuration, or is part of a read-only availability group replica or snapshot.
Step-by-Step Resolution Guide
Step 1: Verify the Current Database State
- Open SQL Server Management Studio (SSMS) or a query window connected to the SQL Server 2025 instance.
- Run the following query to confirm the read-only status:
SELECT name, state_desc, is_read_only
FROM sys.databases
WHERE name = 'YourDatabaseName';
- Confirm that
is_read_onlyreturns1before proceeding.
Step 2: Set the Database to Read-Write Mode
- Ensure no active connections or availability group dependencies are locking the database.
- Place the database into single-user mode and disable read-only status using the following commands:
ALTER DATABASE YourDatabaseName SET READ_WRITE WITH ROLLBACK IMMEDIATE;
- If the database is part of an Availability Group or part of a log-shipping secondary, remove it from that configuration temporarily, as these configurations enforce read-only state on replicas.
Step 3: Re-run the Repair Statement
- With the database now in read-write mode, execute the DBCC repair command again:
DBCC CHECKDB ('YourDatabaseName', REPAIR_ALLOW_DATA_LOSS);
- Monitor the Messages tab in SSMS or the SQL Server error log located at
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOGfor successful completion output.
Step 4: Restore Original Database Settings
- Once the repair process completes successfully, revert the database back to multi-user mode:
ALTER DATABASE YourDatabaseName SET MULTI_USER;
- If the database was originally intended to be read-only (e.g., for a reporting replica), reapply the
READ_ONLYsetting only after confirming the corruption has been resolved:
ALTER DATABASE YourDatabaseName SET READ_ONLY;
Alternative or Verification Steps
- To verify the fix, re-run
DBCC CHECKDB ('YourDatabaseName') WITH NO_INFOMSGS, ALL_ERRORMSGS;and confirm that zero allocation or consistency errors are returned. - If the database still fails to switch to read-write mode due to file-level locks, check Windows Server 2025 Task Manager or
Resource Monitorfor open handles on the.mdf/.ldffiles and restart the SQL Server service (services.msc> SQL Server (MSSQLSERVER) > Restart) before retrying.