0

I've an app written in Xamarin.Forms to create a new sqlite db in my Android device. I use this code:

string dbPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
database = new SQLiteAsyncConnection(dbPath);
database.CreateTableAsync<TodoItem>().Wait();

The database is created correctly, but I cannot find it on specified path (in this case '/data/data/Todo.Android/files/TodoSQLite.db3')

I searched using File Explore, but nothing. So, where is located this file?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Innova
  • 334
  • 4
  • 18

2 Answers2

3

The database is created correctly, but I cannot find it on specified path (in this case '/data/data/Todo.Android/files/TodoSQLite.db3')

Just from your code, I didn't see you create or successfully connected to your TodoSQLite.db3 file, you just find the folder path where your db should be placed.

I don't know how you think your db is correctly created, but if you use Environment.SpecialFolder.Personal, then the path you trying to access is right, but since you couldn't find your db file, I can only imagine that you actually didn't create your db correctly.

You may code for example like this to create a db with file name "TodoSQLite.db3":

string dbPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
database = new SQLiteAsyncConnection(System.IO.Path.Combine (dbPath, "TodoSQLite.db3"));
database.CreateTableAsync<TodoItem>();
Grace Feng
  • 16,564
  • 2
  • 22
  • 45
  • @KronosInformatica, try to use DDMS to see your file. – Grace Feng Aug 03 '17 at 08:00
  • Through file explorer I cannot see '/data/data' folder. After many search over internet, I found that I'm unauthorized to access to this folder. Instead, if I try to create the file in another folder (like '/storage/sdcard0'), I can see it. – Innova Aug 03 '17 at 08:22
  • @KronosInformatica, as I've said, you can use DDMS to check your file under the folder `Personal`, if you want to see let your user see this file, you can change the file path, it's OK. Basically the point of my answer is that you didn't create that file under the path, understand? – Grace Feng Aug 03 '17 at 08:36
0

Did you look for the file in the root directory?

The first data folder should be in the root directory (/) with folders like dev, etc and system. You might have searched for the folder in your phone storage directory (like /storage/emulated/0). As far as I know, you can only access the root directory with a rooted phone.

If you want to get the file:
You could try using a different file explorer but the app data is usually still hidden for non-rooted phones.

Or get the file using your computer.

Teras23
  • 1
  • 1