Sidharth Dash Sidharth Dash - 28 days ago 9
Android Question

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

I am getting an error while connecting to Sqlite DB in android through command prompt.

Here are the steps I have followed:


  • I have created Sqlite DB through java program in android. Created table and inserted data into it. Executed query to get data. Everything fine!!!!

  • Tried to conned to DB though Command Prompt :

    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 screenshot for better understanding but i dont know why its not working(may be becuase of my office firewall).

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


So where am I doing worng?

Note: The database is present having one sample table and i can read write data into that table.

Answer

It looks like my very same problem not long ago.

You may test something first. Once you're connected to the device with adb shell, try ls data/data/<application_namespace_id>/databases/. If it returns opendir failed, Permission denied, it should be the same problem I had: ADB permissions issue. And here's what solved my problem:

  1. Go to 'Developer Options' in your device (If you it isn't visible go to 'Settings' > 'About phone' in your phone and tap 'Build number' several times until 'Developer Options' are enabled)
  2. Then make sure 'Developer Options' are actually enabled
  3. On 'Developer Options' screen, enable 'Android debugging' to allow Android debug
  4. On same screen, make sure ADB has permissions in 'Root access'

Now, try again your commands. But once you enter adb shell also enter su to enable Super User mode. You should see a # confirming your shell on Super User mode.

If you have only one device connected, it should work now. Otherwise, you should also confirm if you're connected to the right device by listing your devices first running adb devices and connecting to right one adb -d <device_reference_here> shell.

You'll probably also need your phone rooted to do any of this.

Hope it helps. Cheers!