【问题标题】:SQLite database connection error Xamarin forms pclSQLite 数据库连接错误 Xamarin forms pcl
【发布时间】:2017-06-24 11:17:39
【问题描述】:

我在 Xamarin 表单 pcl 中包含 SQLite 数据库时遇到问题。与iOS相关。 阅读官方网站上的指南告诉我将其放入图书馆/数据库,但我无法访问。它不连接。代替 Android 工作。

我的错误:

SQLite.SQLiteException:无法打开数据库文件:/Users/my-user/Library/Developer/CoreSimulator/Devices/51FE586C-FA4D-4B13-BE27-5E3AF8D2A51E/data/Containers/Data/Application/82A0DF5E-229F- 4E4A-9A7D-25099D130AA6/Documents/Library/FimapDB.db3(无法打开)

我的代码:

  var dbName = "FimapDB.db3";
        string personalFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
        string libraryFolder = Path.Combine(personalFolder, "Library");
        var path = Path.Combine(libraryFolder, dbName);
        return new SQLiteConnection(path);

我在哪里设置了我的数据库:

我哪里错了?

【问题讨论】:

    标签: c# sqlite xamarin.ios xamarin.forms portable-class-library


    【解决方案1】:

    您需要将数据库复制到设备上的正确文件夹中,以便您可以访问它。

    可以在 Xamarin 论坛上找到答案:https://forums.xamarin.com/discussion/4238/how-can-i-access-an-already-existing-sqlite-database-in-mono-for-android

    【讨论】:

    • 我尝试了xamarin论坛的解决方案,但没有成功。我将数据库放在根文件夹中,现在可以工作了……我不知道是因为这个,但是可以工作。
    猜你喜欢
    • 1970-01-01
    • 2021-08-13
    • 2018-08-11
    • 1970-01-01
    • 1970-01-01
    • 2021-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多