0

Install SQL Server CE database in a separate folder, and application in other folder as usual. 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 .

How can I do this using C#, Windows Mobile 6?????

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
code_star_net
  • 213
  • 7
  • 23
  • What are you installing with? Cab Wiz? –  Oct 31 '11 at 14:20
  • I Created A CAB Project,Added Primary Output and all Required Dependencies.Can i Specify the Database file to be installed out of the Application[and must need that database file Path for connecting with app].? while uninstalling ,Keep Database file in the Device.When ReInstall,If database file exist in that Path,keep that Database file instead of new File.and use with that. – code_star_net Nov 01 '11 at 05:27

1 Answers1

0

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)

  • 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? thread.

Community
  • 1
  • 1
  • Another comment with a helpful link: http://www.mobilepractices.com/2008/10/setupdll-sample-and-walkthrough-terms.html –  Nov 01 '11 at 21:40