Database cannot be upgraded because it is read-only or has read-only files. Make the database or files writeable, and rerun recovery
I just found a post that answered this question:
This may not work in all cases, but I was trying to install the Semantic Search Database and got the same error.
You have to run SQL Server Management Studio as an administrator, and it works.
This isn't an access issue. The problem is that you are attaching the database to a higher version of SQL Server than the instance the .mdf
was originally attached to and it's read only. SQL Server is trying to upgrade the database as part of the attach and can not because the db is in read-only mode.
If your database is in READ_ONLY
(which sounds like it is the case based on your error messages), then you need all files (both log and data) to attach it per the Technet documentation. If you look under the FOR ATTACH
clause, it explicitly describes that:
...for a read-only database, the log cannot be rebuilt because the primary file cannot be updated. Therefore, when you attach a read-only database whose log is unavailable, you must provide the log files or files in the
FOR ATTACH
clause.
You need the accompanying .ldf
for the database. I would contact whoever provided the database and ask them to provide both the .mdf
and .ldf
files. Then, you can attach it with the following syntax:
CREATE DATABASE [foo]
ON (FILENAME='<<path to mdf>>')
LOG ON (FILENAME='<<path to ldf>>')
FOR ATTACH;
The READ_ONLY
status cannot be removed from the database without attaching it because it is stored in the metadata of the database. To alter it, the database needs to be online and attached.
Another alternative is to ask for a backup of the database. You can work around some of these issues more easily if you're doing a database restore instead of an attach.
- Open up my computer.
- Locate the main folder where you have kept the ".mdf" and ".ldf" file.
- Right click on the folder click on "Properties".
- In the properties window click on "Security"
- Click on "Edit" button
- Enable "Read and execute", "Read", "Write" for the listed users and apply the changes to the following folders till the database files.
- Try to attach the ".mdf" file