Sunday, March 20, 2011

Database [Database_Name] cannot be upgraded because it is read-only or has read-only files

A few days ago I was trying to attach some databases on a SQL Server 2005 instance. The database files were copied over the network and located on a drive on the DBMS server.

Though, while I was trying to attach the databases I was getting an error message of the following type:

Msg 3415, Level 16, State 3, Line 1
Database [database_name] cannot be upgraded because it is read-only or has read-only files. Make the database or files writeable, and rerun recovery.
Msg 1813, Level 16, State 2, Line 1
Could not open new database [database_name]. CREATE DATABASE is aborted.

As the error message was saying, I checked the permissions of the database files and ensured that they were not read-only. Also, the service user account running the SQL Server instance had full access on the files.

As I did not have much time for fully troubleshooting the issue, I provided full access to "Everyone" on all the database files I wanted to attach, and tried again.

Guess what? It worked :)

After the databases were successfully attached, I removed the full access from the "Everyone" entity and so everything was back to normal!



--
My Latest Projects:


[Ad]
Easily secure your SQL Server instances! Try out DBA Security Advisor!
DBA Security Advisor for SQL Server by SQLArtBits
DBA Security Advisor was developed by SQLArtBits. The tool was being carefully developed for an entire year and it contains comprehensive security checks and recommendations based on proven SQL Server security best practices. Feel free to download and use the Community Edition which is free and if you find it useful, you can consider upgrading to the Enterprise Edition!

Artemakis Artemiou [MVP]

Author & Editor

Artemakis Artemiou is a Senior SQL Server Architect, Software Developer and Microsoft Data Platform MVP. He is also an author, regular blogger, president of Cyprus.NET User Group and CY Country leader of INETA-EU. He is also the creator of DBA Security Advisor and In-Memory OLTP Simulator. Artemakis is a frequent guest author of worldwide well-respected online journals where he writes articles focusing on many SQL Server topics.

Reference: The SQL Server and .NET Hub (http://www.sqlnethub.com)

3 comments:

Michael "BickiBoy" Rybicki said...

I had the same issue on SQL Server 2008 R2 today - turns out you don't need to mess with permissions on the files. It's caused by the wonderful UAC crap in Server 2008 R2 - I launched the SSMS as administrator (right-click - warning etc) and it worked perfectly. Thanks Microsoft for misleading us with this article that comes up first in Google search: http://support.microsoft.com/kb/931640

Jignesh Patel said...

OR you can run SSMS as Admininistrator

tig313 said...

Thanks - it solved my issue just opening SSMS as Administrator! :)