Saturday, May 13, 2006

Failed to update database "XXX.MDF" because the database is read-only

After a few hours of Googling and testing things I finally solved this problem so I thought I'd write the solution down both for my own and other's benefit.

What I did to get the error:
I had just done some changes to one of my web sites using Visual Studio 2005 and ASP.NET 2.0 with VB.NET. I have previously used MySQL as a database for this site but thought I would test using SQL Server 2005 Express Edition for a new feature I just added.
As usual I did Build - Publish Web Site and then copied and pasted the published directory to my web server. When browsing any of the web pages that use the SQL Server 2005 database I get this error message: Failed to update database "XXX.MDF" because the database is read-only.

Solution:
From what I found on Google this seems to be a confirmed bug in the beta releases of Visual Studio but should be fixed in the released version, but obviously it is not. There seems to be many ways and suggestions on how to fix this, some very complicated.

This worked for me:
1) Make sure App_Data directory or any contained files does not have file system attribute Read-only set. (I had some files marked as Read-only)
2) Give user ASPNET and NETWORK SERVICE Modify control over the App_Data directory. (I had to add both these)
3) Run IISRESET to restart IIS to refresh its permissions.


Main part of this solution was found in this MSDN forum thread, specifically posts by Thongtap and Justin. Thanks guys!

Labels: ,

30 Comments:

Anonymous Anonymous said...

Thanks, it helped

Thu Nov 09, 10:47:00 PM CET  
Anonymous Anonymous said...

THANK YOU SOOOOO MUCH !

You don't even know how much time you saved me !!!!!!

MAtt in Canada

Sat Nov 18, 04:53:00 AM CET  
Anonymous Anonymous said...

Thank you Very much,

I'm strugeling already over 2 months with SQL 2005 rights when I want to put my sites online. This works great!!

Jelger ITND the Netherlands

Tue Nov 21, 12:46:00 PM CET  
Anonymous Anonymous said...

thankyou, it's very helpfull

Mon Nov 27, 10:56:00 AM CET  
Blogger Max Flodén said...

A big "thank you" to myself for documenting this. I just had this problem again and had completely forgot how I solved it the last time... Then it hit me - I have the solution in my blog! :-)

Tue Dec 05, 01:17:00 AM CET  
Anonymous Anonymous said...

ThankQ! ThanQ!
This has been driving me nuts!

Tue Dec 12, 07:43:00 PM CET  
Blogger Dicky said...

Thank you, it is definite help in my case!

Sat Jan 27, 08:03:00 AM CET  
Anonymous Anonymous said...

heiiiii... it's work!!!!..
Thank you so much.

erwin
indonesia

Thu Mar 08, 08:06:00 AM CET  
Anonymous Chris, UK said...

Thanks for posting this. It solved my problem quickly

Sat Mar 10, 09:53:00 PM CET  
Anonymous Anonymous said...

Very helpful!

I only gave the 'network service' user modify permissions for the app_data folder and subdirectories.

Then i ran iisreset and it worked :)

Thanks!

Wed Mar 21, 03:32:00 AM CET  
Anonymous Anonymous said...

Thanks!.. You are a lifesaver..

Easy guide without any unnecessary bullshit

/Johan

Sat Mar 31, 10:51:00 AM CEST  
Anonymous Anonymous said...

Thanks for the help to what otherwise would be a PITA!

- Doc in Texas

Mon Apr 09, 06:53:00 AM CEST  
Anonymous Anonymous said...

thank you very much my dear.

Thu May 03, 12:38:00 PM CEST  
Anonymous Arlen said...

Woah. This worked. Thanks. ^.^

Sun May 13, 02:18:00 PM CEST  
Blogger Christabel said...

can anyone please help me to set the permissions, so that database wont remain read-only? i'm new to this stuff and am at a complete loss!

Sun Jun 24, 10:04:00 PM CEST  
Anonymous Anonymous said...

Thank you very much. Works for me. Before I found this posting I spent a few painfull hours

Fri Jul 27, 02:07:00 AM CEST  
Anonymous Anonymous said...

Thank you very many for this help! -webmaster student from Finland

Fri Aug 10, 10:37:00 AM CEST  
Anonymous Anonymous said...

Thanks a lot it worked out.

Rahul

Thu Aug 23, 01:26:00 PM CEST  
Blogger Dtorq said...

Excellent one

Thu Sep 13, 07:58:00 AM CEST  
Blogger Dtorq said...

This post has been removed by the author.

Thu Sep 13, 07:58:00 AM CEST  
Anonymous Anonymous said...

Holy crap .. I have been struggling with this for days now. thank you so much for this!!

Tue Oct 09, 08:38:00 PM CEST  
Blogger Claudio M. E. Bastos Iorio said...

THANK YOU VERY MUCH!!! it worked for me too. ADD NETWORK SERVICE, RESET IIS. Thats all!

Wed Oct 10, 02:16:00 PM CEST  
Anonymous Anonymous said...

you are my hero, today ;)
thx

Thu Oct 18, 06:18:00 PM CEST  
Anonymous Anonymous said...

you and google are my best friends!

Thu Nov 29, 02:07:00 PM CET  
Anonymous Moo said...

Ta! Removed read-only and added NETWORK SERVICE did the job. didn't even need to restart iis.

Wed Dec 05, 01:48:00 AM CET  
Anonymous Anonymous said...

Could not remove read only, it would come back every time as half greyed out (due to parent propagated permissions.)

But YES, "ADD NETWORK SERVICE, RESET IIS. Thats all!"

This did it1

Wed Jan 16, 06:10:00 PM CET  
Blogger Jason said...

worked like a charm :)

Mon Mar 17, 07:04:00 AM CET  
Anonymous Asem said...

Thanks a lot... this really worked. However, I noticed that granting permissions for ASPNET account was only necessary. There was no need for the NETWORK SERVICE one.

regards

Wed Apr 16, 07:27:00 AM CEST  
Anonymous Anonymous said...

i'm doing it by

right click the folder App_data, click properties,
select security,
click edit,
and then add the user names : NETWORK SERVICE

after that enabled the modify check box....

reset the IIS...

and..

Yeah...it's Work..!!!! :D

Thank you Very much..!!!

Mon Sep 01, 03:01:00 PM CEST  
Anonymous Anonymous said...

you can use command line commands in your deploy script:

CACLS deploy\App_Data /e /p ASPNET:f
CACLS deploy\App_Data /e /p "NETWORK SERVICE":f

Mon Nov 10, 10:20:00 PM CET  

Post a Comment

Links to this post:

Create a Link

<< Home