SQLite database connection error Xamarin forms pcl

北战南征 提交于 2019-12-12 02:13:01

问题


I have a problem with the inclusion of a SQLite database in Xamarin forms pcl. Related to 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.

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)

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 ?


回答1:


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



来源:https://stackoverflow.com/questions/42086010/sqlite-database-connection-error-xamarin-forms-pcl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!