sqlite - MVVMCross社区SQLite-Net插件-无法打开数据库

标签 sqlite xamarin windows-phone-8.1 mvvmcross

我正在尝试在Windows Phone 8.1上打开数据库文件(foo.db)。使用SQLite-Net插件时,出现以下SQLiteException:无法打开数据库文件:foo.db(CannotOpen)。

这是代码:

public Db(ISQLiteConnectionFactory factory)
{
    try
    {
        const string fileName = "foo.db";
        StorageFolder folder = ApplicationData.Current.LocalFolder;
        using(this.connection = factory.Create(Path.Combine(folder.Path, fileName)))
        {
            //Do SOME STUFF
        }
    }
    catch (Exception ex)
    {
        //SQLiteException: Could not open database file: foo.db (CannotOpen).
    }

}


我已经验证了文件的路径。如果删除社区插件并使用SQLite-net,则不会发生任何异常。

哪里错了?

谢谢。

最佳答案

我不知道是否有帮助,但这就是我处理该问题的方式。

我已经在PlatformSpecific项目中创建了ISQLiteConnection,并将其注册为IOC的类型:

Mvx.RegisterType<ISQLiteConnection>(() => new SQLiteConnection(fullPathtoDbFile));


然后,在我的核心(PCL)项目中,我将其解决:

public ISQLiteConnection GetConnection()
{
    if (_con == null)
    {
        _con = Mvx.Resolve<ISQLiteConnection>(); ;
    }
    return _con;
}



ISQLiteConnection是Cirrious.MvvmCross.Community.Plugins.Sqlite命名空间的一部分。

关于sqlite - MVVMCross社区SQLite-Net插件-无法打开数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26047437/

相关文章:

c# - 卡在 Xamarin AAPT 错误上

c# - 在 WebView 中滚动太快时,通用 Windows Phone 8.1 应用程序崩溃

javascript - 如果不存在则插入行,否则更新 sqlite - JavaScript

php - 使用 PDO 准备 SQL 语句

android - 关于将 Android Backup Service 与 SQLite 数据库一起使用的问题

xamarin - 使用 msbuild 命令行 xcarchive 到 ipa

android - SQLiteDatabase.execSQL 无法按预期方式用于 INSERT INTO 查询

xamarin - 使用 FreshMVVM 实现 MasterDetailPage

c# - 文本 block 不会更新

visual-studio - 解决方案 : Payload contains two or more files with the same destination path 'App.xbf' 中的两个应用