我无法在WP8的Sqlite.net的PCL版本中创建SQLiteConnection [英] I cannot create SQLiteConnection in PCL version of Sqlite.net on WP8

查看:73
本文介绍了我无法在WP8的Sqlite.net的PCL版本中创建SQLiteConnection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 https://github.com/的Sqlite.net的PCL版本. oysteinkrog/SQLite.Net-PCL 以下代码由于某些原因在WP8上无法正常工作:

I'm using a PCL version of Sqlite.net from https://github.com/oysteinkrog/SQLite.Net-PCL This code below doesn't work for some reasons on 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)

我做错了什么? 谢谢!!!

What I am doing wrong? Thank you!!!

推荐答案

@ Sergey-Chesalin谢谢您的回答.我检查发现它不可用时应该创建数据库.经过研究,我发现了为什么它不能正常工作.

@Sergey-Chesalin thank you for your answers. I checked and found that it should create DB when it's not available. After my research I found why it doesn't work as it should.

由于某些原因,它们会在连接字符串中添加其他符号,请参见

For some reasons they add additional symbol to the connection string, see Line 121 in SQLiteConnection.cs and Line 196 in SQLiteConnection.cs. Maybe it works as expected in iOS/Android/WinRT versions of ISQLiteApi implementations, but it doesn't work as it should for Windows Phone.

因此,为了修复它,我更改了此行:

So in order to fix it I have changed this line:

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第12行

这篇关于我无法在WP8的Sqlite.net的PCL版本中创建SQLiteConnection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆