Overview: I'm using SQLLite to query an existing database in a Windows Phone 8.1 solution. 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 .
So far I've attached the database file and my DBHelper class uses the following code to query the data back:
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. The DB file itself is here .
Debugging steps:
What steps should I take to debug the SQLLite "no table" error further?
Exception Detail: The exact detail of the exception is as follows which tells me there is no such 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: (maps the DB data to a 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;
}
}
DB Schema:
DB Location in solution:
According to your github repo your dbpath
represents just the relative path right 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))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.