Deploying a desktop application with SQL Server Express

折月煮酒 提交于 2019-12-05 12:30:18
Merlin

Here is the complete solution I ended up implementing.

  • In the Setup and Deployment project, in the File System section, I added the SQL Server database file (MDF) to the Common Application Data folder. This is not one of the selectable options from the [Right Click]File System On Target Machine\Add Special Folder menu (for some reason), so I had to select Custom Folder from that menu then in the Default Location property, put "[CommonAppDataFolder][Manufacturer][ProductName]". This made a folder in the Common Application Data Folder, wherever it may be on the target machine (C:\Program Data\ for Win 7) for my product.
  • I needed all users to be able to have full access to this folder for the SQL Server database file to successfully attach and work properly, so the next step was to change permissions on this folder.
  • The only way I could find to do that was to write a Custom Action for the Setup and Deployment project. This link gives a good rundown of how to create and add a Custom Action: http://thedotnetway.blogspot.com.au/2008/10/creating-setup-project-in-vs-2008-w.html
  • This link provides the code that needs to be put into the Custom Actions overridden Install method: C# - Set Directory Permissions for All Users in Windows 7
  • I used System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData) in the Custom Action code to specify the Common Application Data folder.

Hopefully that makes life easier for any developers in the future with similar requirements.

There are several options to remedy this situation.

  1. 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.

  2. 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.

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