locked
Table not found in SQLite in Windows Phone 8.1 universal app

    Question

  • I am using an existing database with this code:

    private async void CopyDatabase()
    {
        bool isDatabaseExisting = false;
    
        try
        {
            StorageFile storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync("Database.db");
            isDatabaseExisting = true;
        }
        catch
        {
            isDatabaseExisting = false;
        }
    
        if (!isDatabaseExisting)
        {
            StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("Database.db");
            await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);
        }
    }

    When I install the app on the device, uninstall and then reinstall the app I get this error: table not found.

    When I restart the device and install the error does not occur.

    When I install App coping database and when uninstall app database deleted and catch not deleted and reinstall app , function thinks database is exist and do not copy Database. when I restart device catch removed and function coping database how can solve this ?

    How can I fix this? please help me

    Sunday, November 02, 2014 10:04 AM

Answers

  • I solved this :

    I insert CopyDatabase() function in App.xaml.cs Class whit this work solved my error

    tanx

    • Marked as answer by m.h.bayan8 Friday, November 07, 2014 4:37 PM
    Friday, November 07, 2014 4:37 PM

All replies

  • I suspect since the copy function is async the functions is returning before the copy is complete.  You should make the copyDatabase function return something.  Maybe a boolean so the function will not return before the copy is complete.
    Sunday, November 02, 2014 7:57 PM
  • You may refer to my blogs :

     http://cheahengsoon.weebly.com/blog/using-sqlite-in-your-windows-store-application-part-1

    inside you will get more details about the SQLite.

    Monday, November 03, 2014 7:07 AM
  • Hi m.h.bayan8,

    Please check the database file in your project, its Build Action should be set to Content. See the following images.

    Use the following code to copy your sqlite file into local storage before using it.

    bool isDatabaseExisting = false;
                try
                {
                    var file = await ApplicationData.Current.LocalFolder.TryGetItemAsync("data.sqlite");
                    if (file == null)
                    {
                        isDatabaseExisting = false;
                    }
                    else
                    {
                        isDatabaseExisting = true;
                    }
                }
                catch
                {             
                }
                if (!isDatabaseExisting)
                {
                    StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("data.sqlite");
                    await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);
                }
    

    If I misunderstand you, please feel free to let me know.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Thursday, November 06, 2014 8:55 AM
    Moderator
  • I Test this code but get again this error :

    An exception of type 'SQLite.SQLiteException' occurred in QuranOneAyeh.exe but was not handled in user codeAdditional information: no such table: qurandata

    I guess this error for this lines code :

            StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("Database.db");
            await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);

     and my DataBase files don't very well copy when reinstall my app

    Thursday, November 06, 2014 1:46 PM
  • I solved this :

    I insert CopyDatabase() function in App.xaml.cs Class whit this work solved my error

    tanx

    • Marked as answer by m.h.bayan8 Friday, November 07, 2014 4:37 PM
    Friday, November 07, 2014 4:37 PM
  • How you can add this function in App.xaml.cs ?
    Sunday, May 24, 2015 4:23 PM