Sqlite error: cannot open database "/data/data/PackageName/databases/SampleDB.db": cannot open database file

I get an error when connecting to Sqlite DB in android via the command line.

Here are the steps I followed:

  • I created Sqlite DB through a java program in android. Created a table and inserted data into it. A completed query to retrieve data. Everything is fine!!!!
  • I tried to connect to the database, although the command line :

    D:\adt-bundle-windows-x86-20131030\adt-bundle-windows-x86-20131030\sdk\platform-tools> adb shell adb shell root@generic :/ # sqlite3 /data/data/package-name/databases/SampleDB.db sqlite3 /data/data/package-name/databases/Samp ant.encryptdata/databases/Samp <leDB.db SQLite version 3.7.11 2012-03-20 11:35:50 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> .tables .tables SQL Error: unable to open database "/data/data/com.congnizant.encryptdata/databases/SampleDB.db": unable to open database file 1| root@generic :/ # 

Actually, I want to post a screenshot for a better understanding, but I don’t know why it doesn’t work (possibly due to my office firewall).

 Permision for SampleDB is '-rw-rw----'; 

So where do I do worng?

Note: There is one sample table in the database, and I can read the write data to this table.

+4
source share
2 answers

It seems like I have the same problem not so long ago.

You can check something first. When you connect to the device using adb shell , try ls data/data/<application_namespace_id>/databases/ . If it returns opendir failed, Permission denied , it should be the same problem as mine: problems with ADB permissions. And here is what solved my problem:

  • Go to the "Developer Settings" section on your device (if you don’t see it, go to "Settings"> "About Phone" on your phone and click "Build Number" several times until "Developer Settings" is turned on)
  • Then make sure "Developer Options" is indeed enabled.
  • On the Developer Options screen, turn on Android Debugging to enable Android debugging
  • On the same screen, make sure that ADB has permissions in 'Root access'

Now try your commands again. But after entering adb shell also type su to enable superuser mode. You should see a # confirming your shell in superuser mode.

If only one device is connected, it should work. Otherwise, you must also confirm that you are connected to the correct device by specifying your devices that adb devices first start and connect to the right button adb -d <device_reference_here> shell .

You may also need your phone to make one of these.

Hope this helps. Hooray!

+2
source
 I had similar below issue on android emulator: **Issue:** 1)generic_x86:/ $ sqlite3 EmployeeRecords SQLite version 3.9.2 2015-11-02 18:31:45 Enter ".help" for usage hints. 2)sqlite> select * from employee ...> ; Error: unable to open database "EmployeeRecords": unable to open database file **Solution** 1)C:\Users\Hpo\AppData\Local\Android\sdk\platform-tools>adb shell 2)generic_x86:/ $ exit 3)C:\Users\Hpo\AppData\Local\Android\sdk\platform-tools>adb root 4)C:\Users\Hpo\AppData\Local\Android\sdk\platform-tools>adb root restarting adbd as root 5)C:\Users\Hpo\AppData\Local\Android\sdk\platform-tools>adb shell 6)generic_x86:/ # cd /data/data/com.example.hpo.crud_myapplication/databases/ 7)generic_x86:/data/data/com.example.hpo.crud_myapplication/databases # sqlite3 EmployeeRecords 8)sqlite> select * from employee ...> ; 1|sachin|15000 and it working. 
+3
source

All Articles