After spending many hours developing my software, it was time to construct the Setup and Deployment Package. It seemed a simple enough task because visual studios.Net had a built in setup and deployment environment. I quickly opened up a new project selected the setup and deployment wizard and ran though the selections with a silly smirk on my face. I remember thinking to myself, this is so easy, it shouldn’t take more than a few minutes to setup and compile. 

Before you know it, the wizard was finished, I created my shortcuts and added my data file and was ready to go. I quickly installed it on a test machine, clicked the shortcut to run the exe and everything was working perfectly. It even read from the database as a part of the system start-up check list. I was soon prompted to enter a few details to be saved to the database. The database was located in my applications folder in the application data folder.

All the data was entered and it was time to click save. Then it happened, the dreaded error message box showing the proverbial ‘Unable to save data’ error. I was mad as hell with the usual thought floating in my head that it worked perfectly in the development environment, so why the hell isn’t it working now.


In the past I have always installed on Windows XP without any problems worth mentioning but this was my first Vista installation. Boy was I in for a surprise that because of the User Account Control (UAC) that Vista had for security, the way of setting up your applications would be have to be changed.


After digging through my usual checklist of suspected ‘causes of problems’ and ensuring that all the right file permissions were set in the Setup and Deployment project then reinstalling the program, even then the database could not be written to. I finally checked the permissions of my application in the program files folder only to see that it was read only.  I quickly changed the settings on my application folder, giving it read/write permissions only to realize that it could not be changed. I would always be inherited from the Parent Program Files folder.


I tried everything to get it installed, since there was no right click install as administrator allowed on the MSI file, I tried adding the manifest file with all the permissions set for administrator. I tried to use the msiexec.exe along with a bat file with the same result. It installed without the UAC crying about it but the file permissions still remained as read only.

What I learnt after doing many hours of research is that with vista, you are either no longer allowed to read/write to program files folder or I just couldn’t find the solution. Then I luckily came across some valuable information that one must now put any files/databases that needs to be read as well as written to in Vista’s special folders namely AppData Roaming.  I.e. your data files should be stored in the location C:\Users\<user_account>\AppData\Roaming\<app_name>\<db>

I configured the Setup and Deployment project to do just that and voila, the database folder had the correct permissions.  I have listed the instructions on how to configure the setup and deployment project to do that and the code to add to your application which provides a way to reference the AppData folder.

Instructions:

• Visual Studio.Net 2008
• File-> New Project
• Project Types - > Other Project Types
• Select Setup and Deployment
• 4 Folders will be created
o Application Folder
o Common Files Folder
o User’s Desktop
o User’s Programs Menu

How to
• Application Folder – Right Click -> Add-> Project Output  (All project  dependencies should be loaded as well).
• Right click on project output file and select create shortcut to primary output and drag it to user’s desktop
• Again right click on project output file and select create shortcut to primary output and drag it to user programs menu
• Right click on the File System on Target Machine
o Select Add Special Folder - > User’s Application Data Folder
o Right click on User’s Application Data Folder -> Add Folder (Rename Folder to your Application Name)
o Right click on the Folder -> Add File (add your database file to that folder)
o This folder will have read/write access

Build your setup and deployment project.

Configure your connection string to point to that folder and database location.
You can use this sniplet of code yo get the path of the application data folder
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)