Reputation: 157
I have developed a C# 4.0 desktop application that uses a SQL Server Express 2005 database. I have built a Setup and Deployment (msi) package that installs the application and all it's depenedencies, including the mdb database file, into a working folder under the Program Files directory.
The connection string is like this:
Server=.\SQLExpress;AttachDbFilename=|DataDirectory|MyDB.mdf;Database=MyDB;integrated security=true;user instance=true;
The first time a database call is made, the database gets connected to the local SQL Server Express instance.
The installer works as expected on XP computers, however, when tested on Windows 7 machines an exception is thrown the first time a database call is made, which states that there are insufficient permissions on the folder containing the mdb file.
Between Windows XP and Windows 7, windows seems to have locked down permissions on Program Files subfolders. I can solve the problem by setting full permissions to the installation directory, but that seems like cheating.
So my question is this: How should I be configuring the setup and deployment package for this application? Am I doing it right? Do I just need to grant full permissions to all users on the applications directory? If so, how do I achieve this with a VS2010 setup and deployment package? Or should I place the mdb file somehwere else? Or am I totally going about things the wrong way?
Upvotes: 4
Views: 8963
Reputation: 157
Here is the complete solution I ended up implementing.
Hopefully that makes life easier for any developers in the future with similar requirements.
Upvotes: 3
Reputation: 11591
There are several options to remedy this situation.
If your application is only perform reading files from the program files. You would just need to run the setup package under Administrator right ( Right click on it , and then select Run as Administrator). Your Db will be written to the expected location.
If you need to perform IO operation (read/write) on files, then you need to put all your files to either Program Data folder
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
or the current user's data folder
**Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)**
Cheers.
Upvotes: 2