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 line
Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(fileName)
wants an existing file to execute correctly. Correct then your if
condition with:
if (FileExists(dbPath).Result)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.