sqlite db exception : Could not open database

2k views Asked by At

Following error is comming while running my application :

'/data/data/in.acme.www.solarproject/databases/SolarDatabase.sqlite'.
    android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
            at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
            at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
            at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:807)
            at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:792)
            at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:697)
            at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:672)
            at in.acme.www.solarproject.database.DBHelper.checkDataBase(DBHelper.java:81)
            at in.acme.www.solarproject.database.DBHelper.createDataBase(DBHelper.java:49)

    try{
        String myPath = DATABASE_PATH + DATABASE_NAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null,
                SQLiteDatabase.OPEN_READWRITE);  // (DBHelper.java:81)

    }catch(SQLiteException e){
        //TODO: Add exception
        e.printStackTrace();
    }

i had copied my db to assets folder, from their i query for the getDbrecords()

SQLiteDatabase mReadableDB= mDbHelper.getReadableDatabase();
try{
    mCursor=mReadableDB.rawQuery("SELECT * FROM DepartmentMaster ",null); 

from there exception is comming .Please help to resolve it .

1

There are 1 answers

1
ᴘᴀɴᴀʏɪᴏᴛɪs On

Few things you could try:

  1. Try opening it with SQLiteBrowser to see that it's not corrupt
  2. Make sure it's in the right path
  3. Ensure it has the right permissions for read/write
  4. Ensure you have this permission in your manifest file <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />