1

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)

error line

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?

4
  • Why do you use File.Exists without passing the path used to create the file? Commented Nov 26, 2014 at 16:03
  • @Steve I just corrected that now and the same error still persist Commented Nov 26, 2014 at 16:07
  • The ! operator will flip the result so if FileExists returns false then the code will run which is not what you want I think. Commented Nov 26, 2014 at 17:07
  • :-) how come I missed that Commented Nov 26, 2014 at 18:45

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.