简体   繁体   English

在取消Windows移动应用程序标准的同时,如何使SQL CE数据库与现有的DataOn设备保持一致?

[英]While unsitalling the Windows mobile application , how to Keep SQL CE Database with Existing DataOn device?

I have a Windows mobile 6 application.When a new patch is Available on server it will download the New Cab file and install progrmatically on the device with the below Code 我有一个Windows mobile 6应用程序,当服务器上有可用的新补丁程序时,它将下载New Cab文件并使用以下代码在设备上进行编程安装

Process proc = Process.Start("wceload.exe", "\"" + Path.Combine(applicationPath, updateFileName) + "\"");
  proc.WaitForExit();

But this is deleting The existing Database[Sql CE] and Valuable Datas also. 但是,这也删除了现有的数据库[Sql CE]和有价值的数据。

I need to keep the Database On device and uninstall the application and install the new cab file where no need to install the Fresh DB again along with NEW cab installation... 我需要将数据库保留在设备上并卸载应用程序并安装新的cab文件,而无需在安装新的cab时再次安装Fresh DB。

How can i achieve this...help me on this???? 我如何实现这一目标...对此有帮助吗????

Before unstalling, backup the database file (typically .sdf). 取消安装之前,请备份数据库文件(通常是.sdf)。 After the installation, replace the new database file with your backup. 安装后,用备份替换新的数据库文件。

// backup the CE database
string databasePath = ""; // location of your database
string backupPath = ""; // choose a backup path
try
{
    File.Copy(databasePath, backupPath);
}
catch 
{
    Trace.TraceError("Error creating backup");
}


Process proc = Process.Start("wceload.exe", "\"" + Path.Combine(applicationPath, updateFileName) + "\"");
proc.WaitForExit();

Then, after re-installation, delete the new CE database and restore your backup: 然后,在重新安装后,删除新的CE数据库并还原您的备份:

if (File.Exists(databasePath))
{
    try 
    {
         File.Delete(databasePath);
    }
    catch 
    {
         Trace.TraceError("Error deleting new database");
    }
}

string databasePath = ""; // location of your database
string backupPath = ""; // choose a backup path
try
{
    File.Copy(backupPath , databasePath);
}
catch 
{
    Trace.TraceError("Error restoring backup");
}

If you can't delete the new database because it is in use, you'll need to come up with a mechanism to work around that (for example, renaming the new DB, then copying your backup, and then rebooting your application/device) 如果由于正在使用而无法删除新数据库,则需要提供一种解决该问题的机制(例如,重命名新数据库,然后复制备份,然后重新启动应用程序/设备)

The code by digginforfire will allow you to prevent this database from being deleted. digginforfire的代码将允许您防止该数据库被删除。

Personally, though, I think it is better to write code that ensures this is not necessary. 不过,就我个人而言,我认为最好编写代码来确保不必这样做。 For example, your application should check for the database's existence in the Application Data folder before it attempts to load it. 例如,您的应用程序在尝试加载数据库之前,应在“ Application Data文件夹中检查数据库是否存在。 If the database is not there, you simply create it. 如果数据库不存在,则只需创建它。

Copying and modifying a version of Microsoft's example found >> HERE << , you'd have something like this: 复制和修改>>在这里<<的Microsoft示例的版本,您将具有以下内容:

string appPath = string.Format(@"{0}{1}{2}{1}{3}",
    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
    Path.DirectorySeparatorChar, "MyCompany", "MyProduct"
  );

string dbFile = "database.swf";
string dbFilePath = Path.Combine(appPath, dbFile);
if (!File.Exists(dbFilePath)) {
  string connStr = string.Format("Data Source={0}; Password ={1}", dbFilePath, "1234567");
  using (SqlCeEngine engine = new SqlCeEngine(connStr)) {
    engine.CreateDatabase();
  }
  using (SqlCeConnection conn = new SqlCeConnection(connStr)) {
    try {
      conn.Open();
      using (SqlCeCommand cmd = new SqlCeCommand("CREATE TABLE myTable (col1 int, col2 ntext)", conn)) {
        cmd.ExecuteNonQuery();
      }
    } catch { } finally {
      conn.Close();
    }
  }
}

This will ensure that the database remains after your product is uninstalled. 这将确保卸载产品后数据库仍然存在。

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

相关问题 在具有Windows CE 5的设备上使用SQL Server CE数据库进行CRUD操作 - CRUD Opertaions with SQL Server CE database on device with Windows CE 5 损坏的数据库Sql Server CE(Windows Mobile CE 5.0) - Corrupted Database Sql Server CE (Windows Mobile CE 5.0) 在单独的文件夹中安装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 / Windows Mobile 6.5) - Unable to access database (SQL Server CE / Windows Mobile 6.5) 在Windows Mobile 5上将数据加载到Sql CE数据库的最快方法 - Fastest way to load data into Sql CE database on windows mobile 5 Windows CE设备中的SQL异常 - SQL Exception in Windows CE device 在Windows CE mobile(OS Windows CE)中访问SQLCE(Microsoft Sql Compact Edition)数据库的最快方法是什么? - Which is Fastest way to access SQLCE(Microsoft Sql Compact Edition) Database in Windows CE mobile(OS Windows CE))? 如何将Windows CE c#应用程序连接到数据库SQL Server2008r2 - How to connect windows CE c# application to database SQL Server2008r2 在设备上调试Windows CE 5.0应用程序失败 - Debugging Windows CE 5.0 application fails on device 如何在C#应用程序中验证WP7的SQL SERVER CE数据库? - How validates a database of SQL SERVER CE for WP7 in a C # application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM