Sqlite Returned an Error Code of 14

SQLite returned an error code of 14

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.

Why am I getting an sqlite3 error 14 (unable to open database) when calling step on an sqlite3_stmt?

It's likely SQLite is unable create/write to a required temporary file for the transaction. Check your temp location.

See sqlite3_temp_directory.

android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database still unable to fix issue

Issue: Most of the times SQLiteCantOpenDatabaseException occurs when you are access your sqlite database from multiple threads. Let say you have opened the database in one thread and trying to access the database in another will cause SQLiteCantOpenDatabaseException exception.

Solution: Make a singleton object of your SQLiteOpenHelper class and always use the same instance for multiple threads.

Sample:

DBHelper class:

public class DBHelper extends SQLiteOpenHelper {
private DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

public synchronized static DBHelper getInstance(Context context) {
if (dbHelper == null) {
dbHelper = new DBHelper(context);
}

return dbHelper;
}

@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
//...
}

@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
//...
onCreate(sqLiteDatabase);
}
}

Usage:

private static SQLiteDatabase database;

DBHelper dbHelper = DBHelper.getInstance(context);
if (database == null) {
database = dbHelper.getWritableDatabase();
}

Note: Never close the SqliteDatabase instance yourself android system does it for you.

SQLite error code:14, 'unable to open database file'

Take a look at Technical Q&A 1809: New default journaling mode for Core Data SQLite stores in iOS 7 and OS X Mavericks

Your application may be moving or changing the WAL journal files or SQLite files, or may have made assumptions about the file structure that was valid for versions of Core Data that did not use WAL.

It's also possible that your SQLite database is being corrupted, and the error 14 is SQLite attempting to repair the file when Core Data opens it. This corruption can happen if the application was not shut down properly when a write was happening - and many other circumstances. Not shutting down properly is the most common case on Apple platforms though - for example, if Core Data is writing records and the OS kills the application because it's unresponsive. That can cause corruption.



Related Topics



Leave a reply



Submit