How to browse sqlite data in xamarin?
Asked Answered
G

5

8

I have a list view in my app, some data is saving to the database before populating list view.

My problem is that can't see the data, and how to verify the data is stored in the database.

Gosselin answered 31/10, 2015 at 5:5 Comment(0)
I
6

I am giving the solution for Visual Studio 2015 (worked for Xamarin).

Tools-Android-Android Device Monitor

enter image description here

  • Locate the database file mentioned in above image, and click on Pull button as it shown in image 2.
  • Save the file in your desired location.
  • You can open that file using SQLite Studio or DB Browser for SQLite to verify your data is saved.
Investment answered 5/1, 2018 at 12:6 Comment(1)
It's not a solution if you don't have your device rootedPamphylia
G
4

You can use use a SQLite browser, such as the open-source multi-platform DB Browser for SQLite, or another tool of your choice.

Getting access to the sqlite file is the next thing:

iOS Simulator:

/Users/administrator/Library/Application Support/iPhone Simulator

You can browse simulator files from that directory in Mac OS X.

Android Emulator:

You can use the command line via adb shell command for browsing file system:

ls - list current directory 
cd - change current directory

Once you find the Sqlite file for your app, you can use the pull cmd for copying the file from device (or emulator image):

adb pull /sdcard/file.txt file.txt
Guenna answered 31/10, 2015 at 7:59 Comment(3)
I'm using Genymotion emulator hope the same procedure do with this too , i'm using xamarin.forms android in win 8 pc @RobertN iGosselin
ALL Android emulators use adb in some way, no way around it, Genymotion packages a specific version or your can use the latest one from Google : genymotion.com/#!/support?chapter=adb-connectionGuenna
This worked for me on Android, with some extra step. I have to run "adb root" before running "adb pull..." and when finish i run "adb unroot" (i heard some may have issues debugging in VS if not unroot)Hamlen
K
3

I solved this problem in a few steps:

On Windows:

  1. Download a SQLite viewer, for example SQLiteStudio.

  2. Find where the .db or .db3 file is stored, i did it this way:

     var databasePath = Path.Combine(FileSystem.AppDataDirectory, "localDB.db3");
    
     Console.WriteLine(databasePath);
    
  3. For me the path was: /data/user/0/com.companyname.[name]/files/localDB.db3

  4. Find where the Android Debug Bridge (adb) .exe is stored. For me it was stored at: C:\Users[user]\AppData\Local\Android\Sdk\platform-tools. (AppData is a hidden folder, so make sure that hidden folders are visible.

  5. Open a command prompt at this folder.

  6. Try to copy the database file to a local folder on your machine by entering the following line into the command prompt:

adb pull [path to database] [path to local folder]

results in:

adb pull /data/user/0/com.companyname.[name]/files/localDB.db3 C:\Users\[user]\Desktop

  1. If you get an error "Failed to stat remote object ... Permission denied", you have to make sure you have root permission. To do this, enter the following line in the command prompt:

adb root

  1. Try to copy the file again.

  2. If the file is succesfully copied, open it with SQLiteStudio.

et voila

Kwok answered 30/9, 2021 at 7:3 Comment(1)
adb root return: adbd cannot run as root in production builds ? In Debug mode.Andreasandree
R
2

Here is how you can access the sqlite database file in xamarin forms using Rider IDE:

  • Set your db path
private string GetDatabasePath()
{
    return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "db.db");
}

Logging Environment.GetFolderPath(Environment.SpecialFolder.Personal) prints this path on my device

/data/user/0/com.companyname.landpriceexplorer/files
  • Click the Device File Explorer tab on the right side.

enter image description here

  • Search for the database file in the device file explorer.

enter image description here

  • Double click the file to add to the data source.

  • Open the Database tab and browse your data there.

enter image description here

Rosalynrosalynd answered 9/7, 2021 at 3:34 Comment(0)
B
0

For Visual Studio 2022 I have created extension which gives posibility to read sqlite database. It works on xamarin and maui applications.

https://marketplace.visualstudio.com/items?itemName=BinaryAlchemist.AndroidSqliteLiveReader

Because of permissions this extension works only on emulators and with applications created in debug mode.

User needs to provide a path to the folder where Android Debug Bridge. Select running device and manually input or browse path where database is located.

After clicking get data, extension will download database from the device and load it to grid view

enter image description here

Begrudge answered 24/5, 2024 at 20:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.