When i attaching mdf file to SQL Server i am getting error database cannot be upgraded because it is read only or it has read only file. Make sure Database or files are writeable.

migrated from stackoverflow.com Dec 11 '09 at 6:22

This question came from our site for professional and enthusiast programmers.

  • what version are you upgrading from? & what version are you going to? – Nick Kavadias Dec 12 '09 at 3:57

The database you attach is an previous SQL build. It has to be upgraded and it cannot be upgraded because the file is read only.

before you detach the database in the previous version. Change any read-only file groups to read-write. Microsoft also recommends that you turn on auto-grow if its disabled.

After you've attached the database in the new version, can then change the filegroup back to read-only and disable auto-grow.

I had this issue when attempting to attach a sql server 2000 database to a sql server 2008 r2 server. Checked that nothing had been marked read only. Ran management studio as administrator, problem solved.

The moral of my story is "Try running management studio as administrator while you do it".

  • This saved my butt. Thanks! – Wes Apr 21 '17 at 16:28

In addition to checking any read-write flag on the file, make sure that the security ACLs on the file and the folder that you put it in will allow the login that the SQL Server service is using to access the file. If you are unsure what the acl should look like, find the master.mdf file for your instance, look at the ACL/permissions for that file and then make the permissions for your particular mdf file match.

Also, you don't mention the ldf. If you are expecting the server to automatically create the ldf file, figure out where it will be creating and make sure that sql server can write files at that location. It would be better to create the database by attaching both the mdf and ldf files and NOT rely on SQL Server to create a missing LDF. There may be updates in the LDF that did not make it to your MDF file.

Thanks,Telarian

I had this issue when attempting to attach a sql server 2000 database to a sql server 2008 r2 server. Checked that nothing had been marked read only. Ran management studio as administrator, problem solved.

The moral of my story is "Try running management studio as administrator while you do it".

=> Running SSMS as an Administrator & giving db owner permission to the user by which you are trying to attach the database resolved my problem.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.