locked
DB Issue when making app package RRS feed

  • Question

  • Hi,

    I'm developing a Windows store App using a local db with sqlite, SQLite for Windows Runtime, sql-net and an existing database. When my App starts it checks if the database is loaded on the LocalState folder of the App, if not it makes a copy of the DB included in the solution folder into the local state. The properties of the DB in the solution folder are set into Content, and copy always. When deploying my App using Visual Studio it makes the copy of the db and everything Works all right, but when I make the App package and install it using power Shell the App is not copying the existing DB, instead it looks like it is creating a new DB with any information nor tables at all. Can someone help me solving this issue please?.

    Regards
    Friday, November 29, 2013 7:21 PM

Answers

  • Hello JPCamarena, 

    You set your bd file Build action-->Content & Copy to output Directory --> Copy if newer. Then check if db file is in local folder or not. If available then use it otherwise copy it. For copy db file from package to local folder try this :

     public async void CopyDatabase()
            {
                bool isDatabaseExisting = false;
                try
                {
                    StorageFile storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync("//db file name");
                    isDatabaseExisting = true;
                }
                catch
                {
                    isDatabaseExisting = false;
                }
                if (!isDatabaseExisting)
                {
                    StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("//db file name");
                    await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);
                }
            }
    • Marked as answer by Anne Jing Tuesday, December 3, 2013 6:25 AM
    • Unmarked as answer by Anne Jing Tuesday, December 3, 2013 6:25 AM
    • Marked as answer by Anne Jing Monday, December 9, 2013 1:34 AM
    Saturday, November 30, 2013 4:28 AM