开发者

Access to SQL CE database in Program Files directory

I've read a bit that putting a.NET 2.0 SQL CE database in the program files directory where the application is installed is a bad idea. I'm running int开发者_StackOverflow社区o the following error:

Access to the database file is not allowed. [ File name = C:\Program Files (x86)\MyCompanyName\MyApplicationName\MyCEDatabaseName.sdf ]

So I've heard, put it in Common Application files.... I'm not sure where that is, and I've read that the installer may drop the file there with the same permissions. I've also read that people have moved their file there and had issues.

Is it possible to change the ACLs of the file in the program files directory when the installer drops it there? I already have hooks into the application from the MSI to collect and set configuration options. I haven't found a good example of how to change the permissions on ONE file.

Then I've read to store it in the user's application data, but if you're installing the application 'for everyone' where will the file go?

Thanks for your time.... confused.


I assume you are using a MSI package. In this case you can use CommonAppDataFolder which is resolved to "C:\ProgramData".

However, this is also a per-machine location, so it requires the same privileges as Program Files. I think you heard about Application Data folder (AppDataFolder) which is a per-user location (something like "C:\Users\\AppData\Roaming"). It doesn't have permission problems.

If you want to use a per-machine location a solution is to use the LockPermissions table: http://msdn.microsoft.com/en-us/library/aa369774(VS.85).aspx

This is a bit complicated because of all the permission flags. So if your setup authoring tool doesn't offer support for setting permissions, I suggest a simpler approach: use xcacls.exe as a custom action: http://support.microsoft.com/kb/318754

This way all users can gain access to your database file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜