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

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.

Leave a Comment