简体   繁体   English

SQLite数据库连接错误Xamarin形式pcl

[英]SQLite database connection error Xamarin forms pcl

I have a problem with the inclusion of a SQLite database in Xamarin forms pcl. 我在Xamarin表单pcl中包含SQLite数据库时遇到问题。 Related to iOS. 与iOS相关。 Reading the guide on the official site tells me to put it into Library / Databases, but I can not make access. 阅读官方网站上的指南会告诉我将其放入“库/数据库”,但无法进行访问。 It does not connect. 它没有连接。 Instead of Android works. 而不是Android的作品。

my error: 我的错误:

SQLite.SQLiteException: Could not open database file: /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 (CannotOpen) 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(CannotOpen)

my code: 我的代码:

  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);

where i have set my database: 我在哪里设置数据库: 在此处输入图片说明

Where i wrong ? 我哪里错了?

You need to copy the database into the correct folder on your device so you can access it. 您需要将数据库复制到设备上的正确文件夹中,以便可以访问它。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM