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
halfer
  • 19,824
  • 17
  • 99
  • 186
Archimede
  • 699
  • 3
  • 15
  • 28
  • It is expected that `GetFileAsync` would fail if the file doesn't exist. What happens if you just continue execution? – Peter Torr - MSFT May 24 '15 at 20:11
  • Thank for your answer! If I continue I see one other error in SQLiteAsync.cs (in public task CreateTableAsync): Exception thrown: 'System.ArgumentException' in mscorlib.ni.dll Ulteriori informazioni: Use of undefined keyword value 1 for event TaskScheduled. How can I solve it? Thank! – Archimede May 24 '15 at 21:35
  • Have you tried debugging your code? You haven't shown the code where you call CreateTableAsync – Peter Torr - MSFT May 25 '15 at 04:37
  • I think, it depends from Visual C++ component missing. I've tried to download another simple project from a tutorial which is sure correct and I see the same warning. Now, the question is, how can I install or link or refer correctly in my project to the Visual C++ 2013 library component? Thank all. PS I've download it from https://www.microsoft.com/it-it/download/details.aspx?id=40784, I've install correctly by double click, but I see now the same warning. – Archimede May 25 '15 at 09:19
  • If you create a new C++ Direct3D app in Visual Studio, can you deploy it successfully to the phone? – Peter Torr - MSFT May 28 '15 at 03:37

1 Answers1

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!!!

JG73
  • 90
  • 1
  • 10