阅读您的评论后,我建议类似以下的东西:
当应用程序被删除时,该数据库将保留。
当应用程序被重新安装,它可以使用所剩下的数据库。
例子:
namespace DBTest1 {
public partial class Form1 : Form {
const readonly string MYDATABASE = "\\Application Data\\DBTest1\\sqlce.db";
private void Form1() {
InitializeComponent();
CreateIfNotThere(DBTest1.Properties.Resources.sqlcedb, MYDATABASE);
}
void CreateIfNotThere(object data, string filename) {
if (String.IsNullOrEmpty(filename)) {
filename = string.Format(@"{0}{1}{2}",
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
Path.DirectorySeparatorChar, "sqlCe.db");
}
if (data != null) {
byte[] array = (byte[])data;
FileInfo file = new FileInfo(filename);
if (!file.Exists) {
using (FileStream fs = file.Create()) {
fs.Write(array, 0, array.Length);
}
}
}
}
// other code
}
如果你想进入编写定制CABWIZ步骤,有一个很好的写了在How to create the inf file for a smart device cab project from command line?线程。
你在安装什么?出租车司机? – jp2code
我创建了CAB项目,添加了主要输出和所有必需的依赖关系。可以指定要从应用程序安装的数据库文件[并且必须需要该数据库文件路径才能与应用程序连接]。同时卸载时,将数据库文件保存在设备中。当重新安装时,如果数据库文件存在于该路径中,则保留该数据库文件而不是新文件,并使用该文件。 –