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