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.
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!
Thanks, it helped
THANK YOU SOOOOO MUCH !
You don’t even know how much time you saved me !!!!!!
MAtt in Canada
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
thankyou, it’s very helpfull
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! 🙂
This has been driving me nuts!
Thank you, it is definite help in my case!
heiiiii… it’s work!!!!..
Thank you so much.
Thanks for posting this. It solved my problem quickly
I only gave the ‘network service’ user modify permissions for the app_data folder and subdirectories.
Then i ran iisreset and it worked 🙂
Thanks!.. You are a lifesaver..
Easy guide without any unnecessary bullshit
Thanks for the help to what otherwise would be a PITA!
– Doc in Texas
thank you very much my dear.
Woah. This worked. Thanks. ^.^
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!
Thank you very much. Works for me. Before I found this posting I spent a few painfull hours
Thank you very many for this help! -webmaster student from Finland
Thanks a lot it worked out.
Holy crap .. I have been struggling with this for days now. thank you so much for this!!
THANK YOU VERY MUCH!!! it worked for me too. ADD NETWORK SERVICE, RESET IIS. Thats all!
you are my hero, today 😉
you and google are my best friends!
Ta! Removed read-only and added NETWORK SERVICE did the job. didn’t even need to restart iis.
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
worked like a charm 🙂
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.
i’m doing it by
right click the folder App_data, click properties,
and then add the user names : NETWORK SERVICE
after that enabled the modify check box….
reset the IIS…
Yeah…it’s Work..!!!! 😀
Thank you Very much..!!!
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
Thanks a lot!
What if this happens on a Windows application instead of a Web application? Any idea how to solve it?
Thanks! It works!
I encountered the same problem with a Windows application on Vista after applying SQL Express SP3. For some reason, the account used to access the database no longer has write access to the database. To overcome this, I manually granted write access to the Windows Users group on the database. That seems to do the trick, but I’m not sure whether it’s a good security practice.
THX THX THX!!!
Did a website deploy and after I copied the files (including MDF) the “DB is readonly” error was displayed.
I don’t know how to do “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.” steps
Big Big Big thanks for help me !!!
Thanks a lot….. This worked for me…
this same problem is occurred in my windows database application .Could you please give your suggestion.
thanks a lot…it actually helped!
What if we are having desktop application with this same problem? It does not need app_data and any server except sql…