Failed to update .mdf database because the database is read-only (Windows application)

Deadly 提交于 2019-11-26 12:31:05

问题


I\'ve created a database windows application using in C#. My application is running successfully on Windows XP, but it doesn\'t properly execute on Vista or Windows 7 systems. My application shows a message similar to

Failed to update .mdf database because the database is read-only

Can anyone give me a solution to this?


回答1:


If the MDB file is in your application path, then the default permissions would require elevation of rights to be able to write to the files -- I'd recommend moving the data to the ApplicationData shared folder, where end users will have write permissions by default




回答2:


The big thing that changed between Windows XP and Windows Vista/7 is the introduction of UAC which means that users, even if created as administrators, don't routinely have read/write access to "important" locations such as the %programfiles% (Usually C:\Program Files or C:\Program Files (x86)) directory. This is why your application works on Windows XP and not on Windows Vista.

You need to store your DATA in the %programdata% directory (which is usually C:\ProgramData) if the data is shared between users on the machine or %appdata% (which is usually C:\Users\USERNAME_GOES_HERE\AppData\Roaming) if it is specific to a given user. You'll now no longer encounter the problem of being unable to write to the file.

The reason for this is that by storing data in your programs installation directory you were doing the wrong thing. Windows didn't stop you from doing this previously, but it was fairly widely documented that %programfiles% was not the appropriate place to store data.




回答3:


I ran into this related to localdb, the file is named:

myfolder/mysolution/myproject/App_Data/something.mdf

The way I fixed it is to right-click on the top level folder (myfolder) and then choose Properties, then choose Edit, then select Users, add to users either the Modify permission or both Modify and full control (this is a development environment) and then click apply.

So in other words, in my experience, it doesn't matter what folder you put the localdb in, you just need to give Users permission to write.




回答4:


You should add the Modify permissions for IIS_IUSRS user to *.mdf file.




回答5:


go to the folder Where the program is installed and right click on the database file and Properties -> Security -> Group or Username (Click users one by one and see below for the permissions)

If for the user if not set to full control, then click EDIT -> Select the user and give full control..



来源:https://stackoverflow.com/questions/5713416/failed-to-update-mdf-database-because-the-database-is-read-only-windows-applic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!