簡體   English   中英

如何解決SQLLite“沒有這樣的表”錯誤?

[英]How to resolve an SQLLite “no such table” error?

概述:我正在使用SQLLite查詢Windows Phone 8.1解決方案中的現有數據庫。 我已經調整了這個解決方案 ,將數據庫數據讀回我的項目。 但是當我使用數據庫連接調用ToList()時,我得到一個沒有這樣的數據庫錯誤

到目前為止,我已經附加了數據庫文件,我的DBHelper類使用以下代碼來查詢數據:

        using (var dbConn = new SQLiteConnection(dbPath))
        {
            //No such table error thrown here ->
            List<ZoneInfo> zoneInfo = dbConn.Table<ZoneInfo>().ToList<ZoneInfo>();
            ObservableCollection<ZoneInfo> zoneInfoCollection = new ObservableCollection<ZoneInfo>(zoneInfo);
            return zoneInfoCollection;
        }

這是完整的DBHelper類,它引用我的解決方案中的現有DB文件並將其復制到設備的本地文件夾。 DB文件本身就在這里

調試步驟:

  • 我查看了ZoneInfo類屬性,以檢查它們是否與下面數據庫模式中的每個字段的類型/名稱匹配,並且它們匹配。
  • dbPath名稱與附加的數據庫名稱匹配,因此也不是問題。
  • 我還發現了一個 Android上的SQLLite相關的類似問題 ,這表明我的查詢可能是一個問題。
  • 我還檢查了dbconn變量,它向我顯示了有關錯誤的更多信息:

在此輸入圖像描述 題:

我應該采取哪些步驟來進一步調試SQLLite“無表”錯誤?

異常詳細信息:異常的確切細節如下所示,它告訴我沒有這樣的ZoneInfo表:

SQLite.SQLiteException was unhandled by user code
  HResult=-2146233088
  Message=no such table: ZoneInfo
  Source=Parking Tag Picker WRT
  StackTrace:
       at SQLite.SQLite3.Prepare2(IntPtr db, String query)
       at SQLite.SQLiteCommand.Prepare()
       at SQLite.SQLiteCommand.<ExecuteDeferredQuery>d__0`1.MoveNext()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at SQLite.SQLiteCommand.ExecuteQuery[T]()
       at SQLite.TableQuery`1.GetEnumerator()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at Parking_Tag_Picker_WRT.Helpers.DatabaseHelper.ReadZones(String dbPath)
       at Parking_Tag_Picker_WRT.ViewModel.TagRequestViewModel.InitZoneInfoAsync()
       at Parking_Tag_Picker_WRT.TagRequestPage.OnNavigatedTo(NavigationEventArgs e)
  InnerException: 

ZoneInfo類:(將DB數據映射到類)

public class ZoneInfo
{

    //The ObjectId property is marked as the Primary Key  
    [SQLite.PrimaryKey]
    [Column("results_list_objectId")]
    public string ObjectId { get; set; }

    [Column("results_list_zone")]
    public string ZoneName { get; set; }

    [Column("results_list_tariff_ph")]
    public int? TariffPH  { get; set; }

    [Column("results_list_tariff_pd")]
    public int? TariffPD { get; set; }

    [Column("results_list_restrictions")]
    public string Restrictions { get; set; }

    [Column("results_list_days_of_operation")]
    public string DaysOpen { get; set; }

    [Column("results_list_hours_of_operation")]
    public string HoursOpen { get; set; }



    public ZoneInfo() 
    {

    }


    public ZoneInfo(string objectId, string zoneName, int tariffPH, int tariffPD, 
        string restrictions, string daysOpen, string hoursOpen )
    {

        ObjectId = objectId;
        ZoneName = zoneName;
        TariffPH = tariffPH;
        TariffPD = tariffPD;
        Restrictions = restrictions;
        DaysOpen = daysOpen;
        HoursOpen = hoursOpen;
    }



}

數據庫架構:

在此輸入圖像描述

解決方案中的DB位置:

在此輸入圖像描述

根據你的github repo,你的dbpath只代表右邊的相對路徑Databases/DublinCityCouncilTable.db 現在,為了創建連接,您需要提供復制的數據庫的絕對路徑

using (var dbConn = new SQLiteConnection(Path.Combine(ApplicationData.Current.LocalFolder.Path,@"Databases\DublinCityCouncilTable.db"), true))

暫無
暫無

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

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