locked
How to delete SQLite database file for cleaning up purpose RRS feed

  • Question

  • I notice the problem to add tables after you have created a SQLite Db as below:

    public static string DBPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "MyBiz.sqlite");

    using (var db = new SQLite.SQLiteConnection(DBPath))
     {
            db.CreateTable(tablename);
         db.CreateTable(tablename);
         db.CreateTable(tablename);

    }

    In my case, I have a routine to detect if SQLite file is created. So,how to delete the SQLite DB file for cleaning up like deleting, creating new Db to start fresh.

    Thanks

    Friday, November 22, 2013 1:12 AM

Answers

  • Thanks for the code. I think it should work. I will try it out and report back later.
    • Marked as answer by FireDance Thursday, November 28, 2013 7:41 AM
    Friday, November 22, 2013 9:22 AM

All replies

  • Hello FireDance, 

    try this code :

     if (await DOesfileexist("your db file name"))
                {
                    //file exists & deleted successfully
    
                }
                else
                {
                    //file not exists
                }
    
    public async Task<bool> DOesfileexist(string filename)
            {
                try
                {
                    StorageFile dbfile = await ApplicationData.Current.LocalFolder.GetFileAsync(filename);
                    await dbfile.DeleteAsync(StorageDeleteOption.PermanentDelete);
                    return true;
                }
                catch
                {
                    return false;
                }
            }
    Friday, November 22, 2013 4:27 AM
  • Thanks for the code. I think it should work. I will try it out and report back later.
    • Marked as answer by FireDance Thursday, November 28, 2013 7:41 AM
    Friday, November 22, 2013 9:22 AM