簡體   English   中英

FileNotFoundException錯誤創建數據庫WP8 Sqlite

[英]FileNotFoundException Error creating Database WP8 Sqlite

我正在關注 教程使用SQLite數據庫創建應用程序。

當我執行它時,我得到了指向文件SQLite.cs的 System.IO.FileNotFoundException ,錯誤發生的行顯示在下面的屏幕快照中(在SQLite.cs文件中)

錯誤線

以下是用於創建數據庫的代碼段

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>();
   }
}

和方法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;

        }

我想知道出了什么問題。 有什么幫助嗎?

if (!FileExists(dbPath).Result)行的if (!FileExists(dbPath).Result)是,如果該文件不存在,請連接到數據庫並創建一個表。 所以你的情況是錯的,因為行

Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(fileName)

希望現有文件正確執行。 然后使用以下命令更正您的if條件:

if (FileExists(dbPath).Result)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM