SQL Server Error 3906: Writes Fail Because the Database Is Read-Only

🚨Part of the SQL Server Errors series, the exact messages and what actually causes them.In: High Availability

Your write failed with Msg 3906. Check sys.databases.is_read_only for the named database and confirm you are on the intended instance before changing its access mode.

⚡Check the instance and database named in the failed command, then query sys.databases.is_read_only. If this is a log-shipping secondary restored with STANDBY, read-only access may be intentional. Do not switch it to READ_WRITE until you confirm the database role and restore workflow.

The exact Msg 3906 error

Msg 3906  ·  Level 16  ·  State 1
Failed to update database "Lab1010_3906" because the database is read-only.

Check the database state

Run this on the instance named in the error and confirm the database you intended to write to:

SELECT name, state_desc, is_read_only
FROM sys.databases
WHERE name = N'YourDatabase';

If is_read_only is 1, SQL Server reports that database as read-only. If you expected writes, confirm the server, database name, and recovery or secondary role before changing anything.

UPDATE against the read-only lab databaseexample output
Msg 3906, Level 16, State 1, Server HPAI01, Line 1 Failed to update database "Lab1010_3906" because the database is read-only.

This is the captured HPAI01 result after the disposable lab database was set to READ_ONLY. The failed update left its row unchanged.


If this is a log-shipping secondary

A secondary restored with STANDBY is available for read-only access between transaction-log restores. That read-only state is part of the restore workflow, not a cue to make the secondary writable. Confirm the log-shipping configuration and restore job before changing its state.

See Microsoft Docs: About log shipping.


If this database should accept writes

Only after confirming that this is the intended writable database, and not a log-shipping or other secondary, change its access mode:

ALTER DATABASE [YourDatabase] SET READ_WRITE;

Do not use this as a shortcut to clear the error on a secondary. The command changes the database state; it does not repair the wrong target or restore role.

See Microsoft Docs: ALTER DATABASE (Transact-SQL).


Frequently Asked Questions

Does Msg 3906 mean the SQL Server service account cannot write to the files?
The captured message says the database is read-only. Check the database state and role first; do not assume this is a file-system permission error.
Should I set a log-shipping secondary to READ_WRITE?
Not just to clear Msg 3906. Confirm the secondary’s restore mode and job first. A STANDBY secondary is opened for read-only access between log restores.
When is SET READ_WRITE appropriate?
When you have confirmed the database is meant to accept writes and is not serving as a restore or secondary copy.
Does Msg 3906 explain why the database is read-only?
No. It identifies the write failure and the database’s read-only state. Check the intended instance, database role, and restore workflow to find why it is read-only.

Where To Go Next

Check the database’s role before changing its state.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *