Aytee
Aytee

Reputation: 567

Xamarin Android - where to store Local DB so i can view it

I'm currently saving my local sqlite db in Environment.GetFolderPath(Environment.SpecialFolder.Personal) with this code.

Now i'm trying to copy the Db to my PC so i can watch what's inside it. But i'm not able to see this Folder unless it's rooted.

Where is the best place to save the DB so i can view it every now and then?

Here is my android DB code:

[assembly: Dependency(typeof(SQLite_Android))]

namespace AppName.Droid
{
    public class SQLite_Android : ILocalDb.Interfaces.ILocalDb
    {
        #region ISQLite implementation
        public SQLite.SQLiteConnection GetConnection()
        {
            var sqliteFilename   = "MyDb.db3";
            string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            var path             = Path.Combine(documentsPath, sqliteFilename);
            // Create the connection
            var conn             = new SQLite.SQLiteConnection(path);
            // Return the database connection
            return conn;
        }
        #endregion
    }
}

Upvotes: 1

Views: 820

Answers (1)

Milen
Milen

Reputation: 8877

You can use external storage option:

        var sqliteFilename = "MyDb.db3";
        var extStoragePath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
        var path = Path.Combine(extStoragePath, "MyNewFolder");
        var filename = Path.Combine(path, sqliteFilename);

        // Create the connection
        var conn = new SQLite.SQLiteConnection(path);
        // Return the database connection
        return conn;

This way file will be visible via file explorer

Upvotes: 2

Related Questions