mardi 8 mars 2016

Android - Could not open database in Xamarin.forms (SQLite exceptions)

Sorry if the question is asked before, but i searched very well to handle this problem and i didn't find an answer.

I am handling local database with SQLite in my Xamarin forms project (PCL).

1- The connection is working well in iOS but in android i got this problem (Could not open database file )

enter image description here

  • I also set "ReadExternalStoarage" and "WriteExternalStoarage" permissions.

2- I used another method of creating the connection path which is :

string documentsPath = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);
string path = Path.Combine(documentsPath, "pbcare.db");

by this way the exception happened when dealing with the database ...

        public bool checkLogin (string email, string password)
        {

            if (DB.Table<User> ().Where (user => user.Email == email && user.Password == password)
                            .FirstOrDefault () != null) { // exception caught here
                return true;
            } else {
                return false;
            }
        }

enter image description here

but the table is there in the database.

Note: this second way create the connection even if the database file doesn't exist !

Aucun commentaire:

Enregistrer un commentaire