[英]Install SQL Server CE database in separate folder [Windows Mobile 6 Smart device ap]
Install SQL Server CE database in a separate folder, and application in other folder as usual. 将SQL Server CE数据库安装在单独的文件夹中,并将应用程序照常安装在其他文件夹中。 While uninstalling application from device, database won't delete.
从设备上卸载应用程序时,数据库不会删除。 When reinstalling application on the same device, check if database exist in it [where we saved on first install], if not exist save in common folder for all smart devices [like
\\Program Files\\
], else use existing DB . 在同一设备上重新安装应用程序时,请检查其中是否存在数据库(我们在第一次安装时保存的位置),如果不存在,请保存在所有智能设备的通用文件夹中(例如
\\Program Files\\
),否则请使用现有的DB。
How can I do this using C#, Windows Mobile 6????? 如何使用C#,Windows Mobile 6做到这一点?
After reading your comment, I'd suggest something similar to the following: 阅读您的评论后,我建议类似以下内容:
When your application starts, have it check for the existence of your database at the path you require (or at a path specified in an INI file) 当您的应用程序启动时,让它在所需的路径(或INI文件中指定的路径)中检查数据库是否存在。
If the database is not found, ask the user if the default database should be used (or, just copy it over if they should have no choice). 如果找不到数据库,请询问用户是否应使用默认数据库(或者,如果他们没有其他选择,只需将其复制过来)。
When the application is removed, this database will remain. 删除应用程序后,该数据库将保留。
When your application is reinstalled, it can use the database that was left. 重新安装应用程序后,它可以使用剩余的数据库。
Example: 例:
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
}
If you want to get into writing custom CABWIZ steps, there is a nice write up in the How to create the inf file for a smart device cab project from command line? 如果您想编写自定义CABWIZ步骤, 如何在命令行中为智能设备cab项目创建inf文件中有一个不错的文章? thread.
线。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.