sqlite - 我无法在WP8的PCL版本的Sqlite.net中创建SQLiteConnection

标签 sqlite windows-phone-8 portable-class-library

我正在从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.csLine 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/

相关文章:

c# - SQLite 和 .NET 用户控件

android - 为 Android 预先创建一个 sqlite 数据库是否安全?

Python PermissionError : [WinError 32] The process cannot access the file. ....但我的文件已关闭

c# - PhotoChooserTask 引发的未处理异常

windows-phone-8 - 快速应用程序恢复在 Windows Phone 8 上的密码锁定屏幕下不起作用

c# - StreamReader 和可移植类库

android - 如何使 onUpgrade() 语句在第一次安装时运行?

c# - 当用户在c#中单击它时获取图像的来源

c# - 如何确定可移植类库中的默认编码?

c# - 如何从单元测试中引用 VS 2012 可移植类库?