Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

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

4 Answers 4

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.

share|improve this answer

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.

share|improve this answer

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".

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.