【问题标题】:Xamarin.Android SQLiteConnection cannot open database fileXamarin.Android SQLiteConnection 无法打开数据库文件
【发布时间】:2016-10-20 09:31:08
【问题描述】:

我想打开或创建(如果不存在)数据库文件,但是当我尝试创建 SQLiteConnection 类的新实例时,它会抛出异常,错误代码为 30(误用)amd 无法打开数据库文件.

这是我的代码:

class DatabaseOpen
{
    protected SQLiteConnection db;
    ... // Here are another attributes of the class, which is not relevant to the database connection.
    public DatabaseOpen(String filename="noNameFree") // String filename = "noNameFree"
    {
        String dbPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
        dbPath = Path.Combine(dbPath, filename+".db3");
        Java.IO.File dbFile = Application.Context.GetDatabasePath(dbPath);
        dbFile.Mkdirs();
        var dbObject = new SQLiteConnection(dbPath);
        db = dbObject;
    }
    ... // Here are the other methods of the class which is not relevant to the database connection.
}

在上面的代码中,dbPath 变量设置为以下路径:

/data/data/<AppName>.<AppName>/files/noNameFree.db3

我看不出我写错了什么。我希望有人看到代码的问题。

【问题讨论】:

    标签: android sqlite xamarin xamarin.android sqlite-net


    【解决方案1】:

    我将我的应用程序从 SD 卡移至内部存储,然后它就开始工作了。之后我把它移回我的 SD 卡,它仍然可以工作。我认为在部署时 Visual Studio 没有安装到正确的位置。

    注意: 我认为 SQLite.Net 在这种情况下不会抛出 MISUSE Exception。我将向开发人员提出一个关于此的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-11
      • 2014-08-30
      • 2011-03-17
      • 2012-06-08
      • 2017-04-18
      • 2018-02-22
      相关资源
      最近更新 更多