praeclarum / sqlite-net

Simple, powerful, cross-platform SQLite client and ORM for .NET
MIT License
4.07k stars 1.42k forks source link

Xamarin Forms - Android support #767

Open rcunniffe opened 6 years ago

rcunniffe commented 6 years ago

Hey,

I have been using this plugin for some some, but the playstore now require an app to target android version 7 at a minimum. When i target this, the application cannot "Open the database" it only works for lower version of android.

I get a datapath for android like so Path.Combine(global::Android.OS.Environment.ExternalStorageDirectory.Path, filename);

Then when starting my app try to open the database connection like so

string dbPath = DependencyService.Get<IFileHelper>().GetLocalFilePath("myDbName.db3");
var conn = new SQLiteAsyncConnection(dbPath);            

The exception is:

Unhandled Exception:

SQLite.SQLiteException: Could not open database file: /storage/emulated/0/myDbName.db3 (CannotOpen)

I've also ensure i have read and write ticked for external storage permission. I've been stuck on this for sometime and not sure what to do?

rcunniffe commented 6 years ago

@praeclarum Could you please help me with this one?

Weldryn commented 6 years ago

If you are developing with Xamarin Forms, I suggest using Environment.GetFolderPath(Environment.SpecialFolder.Personal) instead of global::Android.OS.Environment.ExternalStorageDirectory.Path. You probably do not have the write permission on /storage/emulated/0/. From my experience, you can only write in your app folder (and external physical storage)