Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 266
Sidharth Dash Avatar asked Jul 28 '15 09:07

Sidharth Dash


2 Answers

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's working.
like image 58
Nimesh Dadhaniya Avatar answered Sep 20 '22 21:09

Nimesh Dadhaniya


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!

like image 42
JMFG Avatar answered Sep 20 '22 21:09

JMFG