我正在从https://github.com/oysteinkrog/SQLite.Net-PCL使用Sqlite.net的PCL版本
以下代码由于某些原因在WP8上无法使用:
var sqliteFilename = Path.Combine(ApplicationData.Current.LocalFolder.Path, "MyDB.db3");
var db = new SQLiteConnection(new SQLitePlatformWP8CSharp(), sqliteFilename);
我收到此错误:
An exception of type 'SQLite.Net.SQLiteException' occurred in SQLite.Net.DLL but was not handled in user code
Additional information: Could not open database file: C:\Data\Users\DefApps\AppData\{149B7F85-2C71-4BEF-984F-903BA7DB80DA}\Local\MyDB.db3 (CannotOpen)
我做错了什么?
谢谢!!!
最佳答案
@ Sergey-Chesalin谢谢您的回答。我检查发现它不可用时应该创建数据库。经过研究,我发现了为什么它不能正常工作。
由于某些原因,它们会在连接字符串中添加其他符号,请参见Line 121 in SQLiteConnection.cs和Line 196 in SQLiteConnection.cs。也许它可以在ISQLiteApi实现的iOS / Android / WinRT版本中按预期方式工作,但不适用于Windows Phone。
因此,为了修复它,我更改了这一行:
string dbFileName = Encoding.UTF8.GetString(filename, 0, filename.Length);
对此:
string dbFileName = Encoding.UTF8.GetString(filename, 0, filename.Length - 1);
在SQLite.Net-PCL/blob/master/src/SQLite.Net.Platform.WindowsPhone8.CSharpSqlite/SQLiteApiWP8.cs line 12中
关于sqlite - 我无法在WP8的PCL版本的Sqlite.net中创建SQLiteConnection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20873946/