Windows Phone 8.1 WRT & SQLite, error on creating database

0

I'm searching to create a SQLite DB in my Win Phone WRT 8.1 app; I've read this post Create a SQLite Database in Windows Phone 8.1 Class Library and I've tried to write this class:

using SQLite;
using System;
using System.Threading.Tasks;
using Windows.Storage;

namespace Functional_Timer
{
    class DatabaseHelper
    {

        private String DB_NAME = "DATABASENAME.db";

        public SQLiteAsyncConnection Conn { get; set; }

        public DatabaseHelper()
        {
            Conn = new SQLiteAsyncConnection(DB_NAME);
            this.InitDb();

        }

        public async void InitDb()
        {
            // Create Db if not exist
            bool dbExist = await CheckDbAsync();
            if (!dbExist)
            {
                await CreateDatabaseAsync();
            }
        }

        public async Task<bool> CheckDbAsync()
        {
            bool dbExist = true;

            try
            {
                //ERRORE!!!
                StorageFile sf = await ApplicationData.Current.LocalFolder.GetFileAsync(DB_NAME);
            }
            catch (Exception)
            {
                dbExist = false;
            }

            return dbExist;
        }

        private async Task CreateDatabaseAsync()
        {
            //add tables here
            //example: await Conn.CreateTableAsync<DbComment>();
        }

    }
}

And I've called this class with the following instructions in the main page of my app:

this.InitializeComponent();
        commentDataSource = new CommentDataSource(db);

But if I run it I see, in the row with the comment "ERRORE!!!" of the first one, the following message:

Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.ni.dll
Ulteriori informazioni: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)

Why is this? How can I solve it?

Edit

In the console, I see the message:

l'SDK "SQLite.WP81, Version=3.8.10.2" dipende dai seguenti SDK "Microsoft.VCLibs, version=12.0" che non sono stati aggiunti al progetto o non sono stati trovati. Assicurarsi di aggiungere queste dipendenze al progetto o è possibile che si verifichino problemi di runtime. È possibile aggiungere dipendenze al progetto mediante Gestione riferimenti.

But if I try to add this one writing the following command "Install-Package Microsoft.VCLibs.120.SDKReference -PRE" in the package manager console, I see this error:

Install-Package : Unable to find package 'Microsoft.VCLibs.120.SDKReference'

At line:1 char:1

+ Install-Package Microsoft.VCLibs.120.SDKReference -Pre

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception

    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
sqlite
windows-phone-8.1
asked on Stack Overflow May 24, 2015 by Archimede • edited Apr 7, 2020 by halfer

1 Answer

0

I had the same error like you,

I reference "Microsoft Visual C++ 2013 Runtime Package for Windows phone" in my Windows phone Project and "Microsoft Visual C++ 2013 Runtieme package for Windows" y my Windows 8.1 Project and work!!!

answered on Stack Overflow Nov 24, 2015 by JG73

User contributions licensed under CC BY-SA 3.0