Failed to update database because the database is read-only

Here we are going to discuss how to solve the error message “Failed to update database because the database is read-only” that you can face with working with SQL Server. Below the complete text of this error:

Msg 3906, Level 16, State 1, Line 10
Failed to update database "MyData" because the database is read-only.

Of course, experience DBA can say that your database is read-only and you don’t have any way to write into it. All you need is simply mark the database as read-write. That’s it. But still, we are going to show you, how you can solve this issue using simple T-SQL Commands or SQL Server Management Studio .

Failed to update database because the database is read-only – Reproducing

  • Create a database with one table
CREATE DATABASE MyData CONTAINMENT = NONE
ON PRIMARY
( NAME = N'MyData', FILENAME = N'D:BackupsMyData.mdf' , SIZE = 5120KB , FILEGROWTH = 1024KB )
LOG ON
( NAME = N'MyData_log', FILENAME = N'D:BackupsMyData_log.ldf' , SIZE = 2048KB , FILEGROWTH = 10%)
GO
USE MyData
GO
CREATE TABLE tbl_Table (id INT)
GO
  • Mark “MyData” database as ReadOnly
USE master
GO
ALTER DATABASE MyData SET READ_ONLY
GO
  • Insert  any value into the table
USE MyData
GO
INSERT INTO tbl_Table VALUES (1), (2)
GO

After you have executed “INSERT INTO” operation, you will receive the following error  message:

Msg 3906, Level 16, State 1, Line 10
Failed to update database "MyData" because the database is read-only.

Failed to update database because the database is read-only – Solution

We successfully reproduced the error, now let’s solve it using T-SQL Commands

All we need to do is to mark database “MyData” as read-write. We can simply do it using next T-SQL Commands:

USE master
GO
ALTER DATABASE MyData SET READ_WRITE WITH NO_WAIT
GO

Now database “MyData” marked as “read-write”. To be sure that the issue is solved insert  any value into the table.

USE MyData
GO
INSERT INTO tbl_Table VALUES (1), (2)
GO

Failed to update database because the database is read-only

That’s it! All 2 rows were affected successfully!

Using SQL Server Management Studio

The another way to solve “Msg 3906, Level 16, State 1, Line 10 Failed to update database because the database is read-only” is to use SQL Server Management Studio (SSMS) . Follow this simple steps and mark your database “read-write”.

  1. Right-click database you need to mark as read-write
  2. Select “Properties”
  3. In the “Database Properties” window select “Options” tab
  4. Scroll down and find “State” tab, go to “Database Read-Only” statement and select “False”Failed to update database because the database is read-only
[Total: 1    Average: 5/5]

One thought on “Failed to update database because the database is read-only

Leave a Reply

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