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 system
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..
You should add the Modify permissions for IIS_IUSRS user to *.mdf file.
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.
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.
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