How to deploy an SQL Compact Edition database file (.sdf) in the AppData folder? Connection string?

…衆ロ難τιáo~ 提交于 2019-12-21 20:26:11

问题


I'm planning to deploy my DB file in the Users\CurrentUserName\AppData folder, because default User Account Control settings restrict write access to the Program Files directory where my program is installed.
First question - is this correct?

So far, I've created a custom folder, set the DefaultLocation property to [LocalAppDataFolder][ProductName], and put the .sdf file in that folder.
This works in Windows 7, but it doesn't seem to work in Windows XP - I can't find any sign of it being deployed anywhere.

So where and how should I deploy the DB file?

I'm also unsure how to set the connection string to the [LocalAppDataFolder] location - any suggestions?

Edit: The application is a WinForms application which will be downloaded from a website and installed using the installer created with Setup Project.


回答1:


This works for me:

string fileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SqlCe35AddinStore.sdf");

string connString = string.Format("Data Source={0};", fileName);


来源:https://stackoverflow.com/questions/4304246/how-to-deploy-an-sql-compact-edition-database-file-sdf-in-the-appdata-folder

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