SQLite - Could not open database file

I am encoding a Xamarin application for Android and I get an error when trying to create a SQLite database.

Here is my code:

string applicationFolderPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "CanFindLocation"); string databaseFileName = System.IO.Path.Combine(applicationFolderPath, "CanFindLocation.db"); SQLite.SQLite3.Config(SQLite.SQLite3.ConfigOption.Serialized); var db = new SQLiteConnection (databaseFileName); 

Here is the error I get:

 SQLite.SQLiteException: Could not open database file: /data/data/com.xamarin.docs.android.mapsandlocationdemo2/files/CanFindLocation/CanFindLocation.db (CannotOpen) 

I have the same code that works in another Xamarin application and would like to know if there is any exception with some name with the package name?

Thank you in advance

+8
source share
2 answers

Is there a path to the path folder that you provide SQLite? If you have not created the CanFindLocation folder, then opening a connection to this path will fail.

Try:

 string applicationFolderPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "CanFindLocation"); // Create the folder path. System.IO.Directory.CreateDirectory(applicationFolderPath); string databaseFileName = System.IO.Path.Combine(applicationFolderPath, "CanFindLocation.db"); SQLite.SQLite3.Config(SQLite.SQLite3.ConfigOption.Serialized); var db = new SQLiteConnection (databaseFileName); 
+13
source

My problem is with the added option "SQLiteOpenFlags.Create" during initialization.

 SQLiteAsyncConnection database = new SQLiteAsyncConnection(dbPath, SQLiteOpenFlags.Create); 
0
source

Source: https://habr.com/ru/post/975388/


All Articles