【问题标题】:Akavache can not open database fileAkavache 无法打开数据库文件
【发布时间】:2014-05-24 03:57:20
【问题描述】:

我有两个项目——一个 PCL(配置文件 7)和一个 Android 应用程序(以 API 为目标......但顺便说一句,我希望它以 10 为目标)。

PCL 已从 Nuget 安装 akavache。 Android 应用已安装 akavache.sqlite3。对于后者,我还必须引用 Rx-PlatformServices 以便构建项目。

Android 应用引用 PCL。

默认的 Android Activity 上有一个按钮,连接如下:

button.Click += async (sender, e) =>
{
    var d = new DataService();
    await d.SaveData();
    var ss = await d.LoadData();
    button.Text = ss;
};

PCL 具有以下代码。

public class DataService
{
    private IBlobCache blobStore;

    public DataService()
    {
        BlobCache.ApplicationName = "DamienApp";
        this.blobStore = BlobCache.UserAccount;
    }
    public async Task SaveData()
    {
        var data = new Person {Name = "Sienna", Age = 3};
        await this.blobStore
                    .InsertObject<string>("mykey", JsonConvert.SerializeObject(data));
    }

    public async Task<string> LoadData()
    {
        var data = await this.blobStore.GetObjectAsync<string>("mykey");
        return data;
    }
}

public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
}

按下按钮时出现以下错误。

[mono] 未处理的异常:[mono] SQLite.SQLiteException:不能 打开数据库文件:BlobCache/userblobs.db (CannotOpen) [mono] at SQLite.SQLiteConnection..ctor (System.String databasePath, SQLiteOpenFlags openFlags, Boolean storeDateTimeAsTicks) [0x0006d] in /Users/paul/github/Akavache/Akavache.Sqlite3/SQLite.cs:125 [单声道]
在 SQLite.SQLiteConnectionWithoutLock..ctor (SQLite.SQLiteConnectionString 连接字符串,SQLiteOpenFlags 标志)[0x00000] 在 /Users/paul/github/Akavache/Akavache.Sqlite3/SQLiteAsync.cs:344 [单声道] 在 SQLite.SQLiteConnectionPool+Entry..ctor (SQLite.SQLiteConnectionString 连接字符串,SQLiteOpenFlags 标志)[0x0000d] 在 /Users/paul/github/Akavache/Akavache.Sqlite3/SQLiteAsync.cs:330 [单声道] 在 SQLite.SQLiteConnectionPool+c__AnonStorey14.m__25 (Int32 _) [0x00000] 在 /Users/paul/github/Akavache/Akavache.Sqlite3/SQLiteAsync.cs:309 [单声道] 在 System.Linq.Enumerable+c__Iterator10`2[System.Int32,SQLite.SQLiteConnectionPool+Entry].MoveNext () [0x00000] in :0 [mono] at System.C

我想知道这是否是某种安全问题。这一切都在运行我拥有 root 访问权限的手机(Galaxy note 2)。

有什么想法吗?

提前致谢。

【问题讨论】:

    标签: android sqlite mono xamarin


    【解决方案1】:

    距您提出要求已有一百万年了,但您可能没有设置应用程序名称:

    BlobCache.ApplicationName = "MyAppName";
    

    【讨论】:

    • 哈!谢谢保罗。看 - 有一段时间了,我最终只是自己动手。不过,从记忆中,我“记得知道”需要设置 ApplicationName,所以我的直觉是它是另一回事。不过你可能是对的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-11
    • 2014-08-30
    • 2011-03-17
    • 2012-06-08
    • 2017-04-18
    • 2018-02-22
    相关资源
    最近更新 更多