繁体   English   中英

在单独的文件夹中安装SQL Server CE数据库[Windows Mobile 6 Smart device ap]

[英]Install SQL Server CE database in separate folder [Windows Mobile 6 Smart device ap]

将SQL Server CE数据库安装在单独的文件夹中,并将应用程序照常安装在其他文件夹中。 从设备上卸载应用程序时,数据库不会删除。 在同一设备上重新安装应用程序时,请检查其中是否存在数据库(我们在第一次安装时保存的位置),如果不存在,请保存在所有智能设备的通用文件夹中(例如\\Program Files\\ ),否则请使用现有的DB。

如何使用C#,Windows Mobile 6做到这一点?

阅读您的评论后,我建议类似以下内容:

  • 当您的应用程序启动时,让它在所需的路径(或INI文件中指定的路径)中检查数据库是否存在。

  • 如果找不到数据库,请询问用户是否应使用默认数据库(或者,如果他们没有其他选择,只需将其复制过来)。

删除应用程序后,该数据库将保留。

重新安装应用程序后,它可以使用剩余的数据库。

例:

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步骤, 如何在命令行中为智能设备cab项目创建inf文件中有一个不错的文章? 线。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM