SQLite database connection error Xamarin forms pcl

2019-09-13 23:55发布

问题:

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