简体   繁体   English

FileNotFoundException错误创建数据库WP8 Sqlite

[英]FileNotFoundException Error creating Database WP8 Sqlite

I am following 我正在关注 this tutorial to create an application with an SQLite database. 教程使用SQLite数据库创建应用程序。

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) 当我执行它时,我得到了指向文件SQLite.cs的 System.IO.FileNotFoundException ,错误发生的行显示在下面的屏幕快照中(在SQLite.cs文件中)

错误线

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 和方法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. if (!FileExists(dbPath).Result)行的if (!FileExists(dbPath).Result)是,如果该文件不存在,请连接到数据库并创建一个表。 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条件:

if (FileExists(dbPath).Result)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM