[英]How to resolve an SQLLite “no such table” error?
Overview: I'm using SQLLite to query an existing database in a Windows Phone 8.1 solution. 概述:我正在使用SQLLite查询Windows Phone 8.1解决方案中的现有数据库。 I've adapted this solution to read the database data back to my project.
我已经调整了这个解决方案 ,将数据库数据读回我的项目。 But when I call ToList() using the DB connection I get a no such database error .
但是当我使用数据库连接调用ToList()时,我得到一个没有这样的数据库错误 。
So far I've attached the database file and my DBHelper class uses the following code to query the data back: 到目前为止,我已经附加了数据库文件,我的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;
}
This is the complete DBHelper class which reference the existing DB file from my solution and copies it to the device's local folder. 这是完整的DBHelper类,它引用我的解决方案中的现有DB文件并将其复制到设备的本地文件夹。 The DB file itself is here .
DB文件本身就在这里 。
Debugging steps: 调试步骤:
What steps should I take to debug the SQLLite "no table" error further? 我应该采取哪些步骤来进一步调试SQLLite“无表”错误?
Exception Detail: The exact detail of the exception is as follows which tells me there is no such ZoneInfo table: 异常详细信息:异常的确切细节如下所示,它告诉我没有这样的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 Class: (maps the DB data to a class) 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 Schema: 数据库架构:
DB Location in solution: 解决方案中的DB位置:
According to your github repo your dbpath
represents just the relative path right Databases/DublinCityCouncilTable.db
. 根据你的github repo,你的
dbpath
只代表右边的相对路径Databases/DublinCityCouncilTable.db
。 Now for creating your connection you would need to provide the absolute path to your copied datatbase which would be 现在,为了创建连接,您需要提供复制的数据库的绝对路径
using (var dbConn = new SQLiteConnection(Path.Combine(ApplicationData.Current.LocalFolder.Path,@"Databases\DublinCityCouncilTable.db"), true))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.