Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite returned an error code of 14

I am trying to copy an existing database from my assets folder and execute some operations on it. Everything is working fine but I've gotten the following error in the log files of my emulator:

sqlite returned: error code = 14, msg = cannot open file at source line 25467

09-06 11:23:41.844: INFO/Database(22560): sqlite returned: error code = 14, msg = cannot open file at source line 25467
09-06 11:23:41.885: ERROR/Database(22560): sqlite3_open_v2("/data/data/com.dhani.Lazy/databases/LazyDB.sqlite", &handle, 1, NULL) failed
09-06 11:23:41.885: WARN/System.err(22560): android.database.sqlite.SQLiteException: unable to open database file
09-06 11:23:41.894: WARN/System.err(22560):     at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
09-06 11:23:41.904: WARN/System.err(22560):     at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1849)
09-06 11:23:41.914: WARN/System.err(22560):     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
09-06 11:23:41.914: WARN/System.err(22560):     at com.dharani.LazyApple.Database.DataBaseHelper.checkDataBase(DataBaseHelper.java:72)
09-06 11:23:41.914: WARN/System.err(22560):     at com.dharani.LazyApple.Database.DataBaseHelper.createDataBase(DataBaseHelper.java:47)
09-06 11:23:41.914: WARN/System.err(22560):     at com.dharani.LazyApple.Database.DataBaseHelper.Login(DataBaseHelper.java:166)
09-06 11:23:41.914: WARN/System.err(22560):     at com.dharani.LazyApple.Views.LoginView$1.onClick(LoginView.java:63)
09-06 11:23:41.934: WARN/System.err(22560):     at android.view.View.performClick(View.java:2485)
09-06 11:23:41.934: WARN/System.err(22560):     at android.view.View$PerformClick.run(View.java:9080)
09-06 11:23:41.944: WARN/System.err(22560):     at android.os.Handler.handleCallback(Handler.java:587)
09-06 11:23:41.944: WARN/System.err(22560):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-06 11:23:41.944: WARN/System.err(22560):     at android.os.Looper.loop(Looper.java:123)
09-06 11:23:41.944: WARN/System.err(22560):     at android.app.ActivityThread.main(ActivityThread.java:3683)
09-06 11:23:41.964: WARN/System.err(22560):     at java.lang.reflect.Method.invokeNative(Native Method)
09-06 11:23:41.964: WARN/System.err(22560):     at java.lang.reflect.Method.invoke(Method.java:507)
09-06 11:23:41.964: WARN/System.err(22560):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-06 11:23:41.964: WARN/System.err(22560):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-06 11:23:41.964: WARN/System.err(22560):     at dalvik.system.NativeStart.main(Native Method)

Any suggestions on how to solve this problem?

like image 385
Kishore Avatar asked Sep 06 '11 07:09

Kishore


People also ask

What is SQLite error?

The SQLITE_READONLY_CANTLOCK error code is an extended error code for SQLITE_READONLY. The SQLITE_READONLY_CANTLOCK error code indicates that SQLite is unable to obtain a read lock on a WAL mode database because the shared-memory file associated with that database is read-only.

How do I fix database disk image is malformed?

You may see the "database disk image is malformed" error in TekRADIUS log. This could happen during unplanned shutdown or reboot. The error indicates that one or more of the sqlite3 databases may have become corrupted. You need to have sqlite3.exe to diagnose and fix the problem.

What is sqlite3_step?

The sqlite3_step() runs the SQL statement. SQLITE_ROW return code indicates that there is another row ready. Our SQL statement returns only one row of data, therefore, we call this function only once. sqlite3_finalize(res); The sqlite3_finalize() function destroys the prepared statement object.


2 Answers

This may be a little late, but hope this helps for whoever gets this problem (since I can't find a definitive solution around).

I think I know the reason for this cause (at least for my case). Looking in the DDMS --> File Explorer, you'd realize that the Database Folder (/data/data//databases/) does not exist, which is why the application cannot create the database file in that non-existent folder. If you can create a databases folder in some manner, you can avoid this problem.

Because I'm lazy, I just used the /data/data//files/ folder when I'm in Emulator mode. You can get the files dir using this:

context.getFilesDir().getPath()

This worked beautifully for me in the Emulator.

Hope this helps someone.

In case you want to see some code:

String dbFilename = "example.db";
try
{       
    File databaseFile = getDatabasePath(dbFilename);        
        SQLiteDatabase _db = SQLiteDatabase.openOrCreateDatabase(databaseFile);
} catch (Exception e)
{
    String databasePath =  getFilesDir().getPath() +  "/" + dbFilename;
    File databaseFile = new File(databasePath); 
    _db = SQLiteDatabase.openOrCreateDatabase(databaseFile);
}

EDIT: I tried logging into Facebook (my app has FB integration) on the Emulator and /databases folder appeared after that (and persisted). Not sure what happened, but it's possible to create that folder somehow. Something for another expert around here to shed light on.

like image 191
El Jae Avatar answered Oct 23 '22 08:10

El Jae


I have seen this error occur if you are using sharedUserId in your manifest. If you change the sharedUserId of an application and reinstall the application it does not have the required ownership to write to the SQLite database.

like image 42
Nic Strong Avatar answered Oct 23 '22 09:10

Nic Strong