2016-03-02 123 views
1

概述: 我正在使用SQLLite查询Windows Phone 8.1解决方案中的现有数据库。我已经调整了这个solution来将数据库数据读回我的项目。但是当我使用数据库连接调用ToList()时,我得到一个没有这样的数据库错误的如何解决SQLLite“没有这样的表”的错误?

到目前为止,我已经附加数据库文件和我的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文件本身是here

调试步骤:

  • 我回顾了区信息类的属性,以确定它们与该类型/名称每个字段在下面的DB模式匹配,和他们相匹配。
  • dbPath名称与附加的数据库名称相匹配,所以这也不是问题。
  • 我还发现一个similar question与Android上的SQLLite相关,这表明它可能是我在桌面上查询时遇到的一个问题。
  • 我还考察了dbconn变量,它让我在错误的详细信息:

enter image description here 问:

我应该采取什么步骤来调试SQLLite“没有表”的错误进一步?

异常详情: 异常的确切细节是如下这告诉我不存在这样的区信息表:

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: 

区信息类别:(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模式:

enter image description here

DB位置的解决方案:

enter image description here

+0

我没有找到数据库中的ZoneInfo表。 –

+0

确定没有,这是我的数据库应该映射到的POCO类的名称。 是否应该与我的db文件名相同? DublinCityCouncilTable –

回答

2

根据您的GitHub库您dbpath仅代表相对路径正确Databases/DublinCityCouncilTable.db。现在创建你的连接,你需要提供绝对路径到你的复制数据库,这将是

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

我再看看我的代码..需要按照上面的示例重新修改它。如果需要,我会将其标记为已接受并发布另一个问题。 –

+0

我从你的编辑发布了一个新问题 - http://stackoverflow.com/questions/35808724/how-to-resolve-an-incorrect-path-to-sqlite-database –