如何解决 SQLLite "no such table" 错误?

How to resolve an SQLLite "no such table" error?

概览: 我正在使用 SQLLite 在 Windows Phone 8.1 解决方案中查询现有数据库。我已将此 solution 改编为将数据库数据读回我的项目。但是 当我使用数据库连接调用 ToList() 时,我得到了一个没有这样的数据库的错误

到目前为止,我已经附加了数据库文件,我的 DBHelper class 使用以下代码来查询数据:

        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 class which reference the existing DB file from my solution and copies it to the device's local folder. The DB file itself is here

调试步骤:

问题:

我应该采取什么步骤来进一步调试 SQLLite "no table" 错误?

异常详细信息: 异常的具体细节如下,它告诉我没有这样的 ZoneInfo table:

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 Class:(将数据库数据映射到 class)

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



}

数据库模式:

数据库在解决方案中的位置:

根据您的 github 存储库,您的 dbpath 仅代表正确的相对路径 Databases/DublinCityCouncilTable.db。现在要创建连接,您需要提供复制的数据库的绝对路径,即

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