I am following this tutorial to create an application with an SQLite database.
When I executed it, I got System.IO.FileNotFoundException pointing to the file SQLite.cs, the line where the error originated is shown in the screen shot below(in the SQLite.cs file)
Below is the code snippet for creating a database
string dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");
if (!FileExists(dbPath).Result)
{
using (var db = new SQLiteConnection(dbPath))
{
db.CreateTable<Person>();
}
}
and the method FileExists
private async Task<bool> FileExists(string fileName)
{
var result = false;
try
{
var store = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
result =true;
}
catch
{
}
return result;
}
I am wondering what went wrong. Any help?
With the line
if (!FileExists(dbPath).Result)
you're saying that if the file doesn't exist, connect to the database and create a table. So your condition is wrong, because the linewants an existing file to execute correctly. Correct then your
if
condition with:if (FileExists(dbPath).Result)