在连接到Windows Phone 8上的本地sqlite数据库时,我遇到了一个奇怪的问题。在使用VS部署后在本地测试应用程序时,我能够连接到数据库而没有任何问题,运行查询。
但是,当我从商店下载后运行应用程序时,尝试连接数据库时收到以下异常:
Could not open database file: 'Version=3,uri=file:mydbname.sqlite' (CannotOpen)
at SQLite.SQLiteConnection.ctor(String databasePath, SQLiteOpenFlags openFlags, Boolean storeDateTimeAsTicks)
我应该注意到,在收到此异常后,查询将通过并返回预期的数据(看似没有问题),这确认了在从商店安装数据库后确实存在db。
异常中的数据库路径与我在调试时看到的路径相同,所以我不确定为什么我会收到错误。我使用的是sqlite-net-wp8 v3.8.4.3。
我看过这篇文章(但似乎并不仅限于商店):I cannot create SQLiteConnection in PCL version of Sqlite.net on WP8
谢谢!
答案 0 :(得分:0)
将我的数据库路径从'Version 3,uri = file:mydbname.sqlite'更改为使用ApplicationData.Current.LocalFolder.Path + 'mydbname.sqlite'
似乎解决了这个问题。