0

I am actually working on a small app and I am emulating it on my Android device (Android 7.1 - clear flashed Android from LineageOS). My problem is that I need to take a look into my SQLite tables, but I can't find the file so I came up with an idea. If I can't look to it, because of Android, let's copy the file to computer.

But to be honest, I don't know how to do that. I found this, but my Xamarin telling me he don't understand that script.

public static void BackupDatabase(string sourceFile, string destFile)
{
    using (SQLiteConnection source = new SQLiteConnection(String.Format("Data Source = {0}", sourceFile)))
    using (SQLiteConnection destination = new SQLiteConnection(String.Format("Data Source = {0}", destFile)))
    {
        source.Open();
        destination.Open();
        source.BackupDatabase(destination, "main", "main", -1, null, -1);
    }
}

He doesn't understands the .Open();....

SQLiteConnection doesn't containts definitions for Open and there is no extending method Open..... (don't you missing some directives?)

3
  • use adb to view the files in your Android emulator image and copy them to your desktop Commented Jun 25, 2017 at 19:45
  • actually my PC is really bad for emulating, it takes really long and in most of times the adb stops responding, that's why i am emulating on real device Commented Jun 25, 2017 at 19:51
  • it works for devices too: stackoverflow.com/questions/17629889/… Commented Jun 25, 2017 at 20:14

2 Answers 2

1

While debugging xamarin forms android application run below commands in command prompt to explore the database content.

C:\Program Files (x86)\Android\android-sdk\platform-tools>adb shell
TC25FM:/ $ run-as com.packagename

Below command copies the database content to phones sdcard

TC25FM:/data/data/com.packagename $ cp files/Storage.db /sdcard/data/
TC25FM:/data/data/com.packagename $ exit
TC25FM:/ $ exit

Below command pulls the file from sdcard to the dev machine

C:\Program Files (x86)\Android\android-sdk\platform-tools>adb pull 
sdcard/data/Storage.db

Below command helps you explore the database using sql queries

C:\Program Files (x86)\Android\android-sdk\platform-tools>sqlite3 Storage.db

sqlite> select * from tablename
Sign up to request clarification or add additional context in comments.

1 Comment

Please add explanation to your answer
0

You can do this on Mac/iPhoneSimulator

var path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); path = Path.Combine(path, "Database.db"); SQLiteConnection source = new SQLiteConnection(path);

You can print out the path and open it in Mac

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.