# net.sqlcipher.database.SQLiteException: error code 14: Could not open database

**URL:** <https://discuss.zetetic.net/t/net-sqlcipher-database-sqliteexception-error-code-14-could-not-open-database/2323>\
**Category:** SQLCipher\
**Created:** [August 22, 2017, 1:52pm UTC](https://discuss.zetetic.net/t/net-sqlcipher-database-sqliteexception-error-code-14-could-not-open-database/2323 "2017-08-22T13:52:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hsvmks](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/hsvmks/32/662_2.png) [@hsvmks](https://discuss.zetetic.net/u/hsvmks)\
**Post date:** [August 22, 2017, 1:52pm UTC](https://discuss.zetetic.net/t/net-sqlcipher-database-sqliteexception-error-code-14-could-not-open-database/2323/1 "2017-08-22T13:52:02Z")

</div>

I am trying to decrypt .db file using sqlcipher.  
Here is my code

Process suProcess=Runtime.getRuntime().exec(“su”);  
DataOutputStream dos=new DataOutputStream(suProcess.getOutputStream());  
dos.writeBytes(“adb shell” + “\n”);  
dos.flush();  
dos.writeBytes("cp “+dbPath+” "+ “/data/data/source.db\n”);  
dos.flush();  
// SystemClock.sleep(5000);  
db=SQLiteDatabase.openOrCreateDatabase(destination,this.dbKey,null,hook);

I am executing this code on every second. For first few time the db decrypted perfectly but after sometime its giving me error below when I try to open db file:

08-21 20:05:08.011 30119-30119/? E/memtrack: Couldn’t load memtrack module (No such file or directory)  
08-21 20:05:08.011 30119-30119/? E/android.os.Debug: failed to load memtrack module: -2  
08-21 20:05:08.032 30137-30137/? D/su: su invoked.  
08-21 20:05:08.032 30137-30137/? D/su: starting daemon client 10026 10026  
08-21 20:05:08.057 30141-30141/? D/su: remote pid: 30137  
08-21 20:05:08.059 30141-30141/? D/su: remote pts\_slave:  
08-21 20:05:08.061 30141-30141/? D/su: waiting for child exit  
08-21 20:05:08.102 30143-30143/? D/su: su invoked.  
08-21 20:05:08.110 30143-30143/? D/su: db allowed  
08-21 20:05:08.110 30143-30143/? D/su: 10026 /system/xbin/su executing 0 /system/bin/sh using binary /system/bin/sh : sh  
08-21 20:05:08.135 30119-30119/? D/AndroidRuntime: Calling main entry [com.android.commands.am.Am](http://com.android.commands.am.Am)  
08-21 20:05:08.184 30119-30136/? I/dalvikvm: Total arena pages for JIT: 11  
08-21 20:05:08.215 30119-30136/? I/dalvikvm: Total arena pages for JIT: 12  
08-21 20:05:08.216 30119-30136/? I/dalvikvm: Total arena pages for JIT: 13  
08-21 20:05:08.225 30119-30136/? I/dalvikvm: Total arena pages for JIT: 14  
08-21 20:05:08.231 30119-30136/? I/dalvikvm: Total arena pages for JIT: 15  
08-21 20:05:08.233 30119-30136/? I/dalvikvm: Total arena pages for JIT: 16  
08-21 20:05:08.236 30119-30136/? I/dalvikvm: Total arena pages for JIT: 17  
08-21 20:05:08.240 30119-30136/? I/dalvikvm: Total arena pages for JIT: 18  
08-21 20:05:08.247 30119-30136/? I/dalvikvm: Total arena pages for JIT: 19  
08-21 20:05:08.255 30119-30136/? I/dalvikvm: Total arena pages for JIT: 20  
08-21 20:05:08.370 30119-30119/? D/AndroidRuntime: Shutting down VM  
08-21 20:05:08.371 30119-30135/? D/jdwp: Got wake-up signal, bailing out of select  
08-21 20:05:08.371 30119-30135/? D/dalvikvm: Debugger has detached; object registry had 1 entries  
08-21 20:05:08.376 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.378 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.378 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.378 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.378 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.378 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.378 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.378 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.378 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.378 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.380 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.384 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.384 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.384 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.384 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.384 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.384 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.384 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.384 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.384 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.384 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.384 30119-30136/? D/dalvikvm: Compiler shutdown in progress - discarding request  
08-21 20:05:08.452 30144-30144/? D/AndroidRuntime: \>\>\>\>\>\> AndroidRuntime START com.android.internal.os.RuntimeInit \<\<\<\<\<\<  
08-21 20:05:08.452 30144-30144/? D/AndroidRuntime: CheckJNI is OFF  
08-21 20:05:08.455 30144-30144/? I/dalvikvm: No library specified. The standard exception handler will be used  
08-21 20:05:08.476 30144-30144/? D/dalvikvm: Trying to load lib [libjavacore.so](http://libjavacore.so) 0x0  
08-21 20:05:08.477 30144-30144/? E/houdini\_hook: Unable to open libdvm\_houdini lib  
08-21 20:05:08.481 30144-30144/? E/houdini\_hook: Unable to open libdvm\_houdini lib  
08-21 20:05:08.481 30144-30144/? E/houdini\_hook: Unable to open libdvm\_houdini lib  
08-21 20:05:08.482 30144-30144/? E/houdini\_hook: Unable to open libdvm\_houdini lib  
08-21 20:05:08.482 30144-30144/? E/houdini\_hook: Unable to open libdvm\_houdini lib  
08-21 20:05:08.483 30144-30144/? E/houdini\_hook: Unable to open libdvm\_houdini lib  
08-21 20:05:08.484 30144-30144/? D/dalvikvm: Added shared lib [libjavacore.so](http://libjavacore.so) 0x0  
08-21 20:05:08.492 30144-30144/? D/dalvikvm: Trying to load lib [libnativehelper.so](http://libnativehelper.so) 0x0  
08-21 20:05:08.492 30144-30144/? E/houdini\_hook: Unable to open libdvm\_houdini lib  
08-21 20:05:08.492 30144-30144/? E/houdini\_hook: Unable to open libdvm\_houdini lib  
08-21 20:05:08.493 30144-30144/? E/houdini\_hook: Unable to open libdvm\_houdini lib  
08-21 20:05:08.493 30144-30144/? E/houdini\_hook: Unable to open libdvm\_houdini lib  
08-21 20:05:08.493 30144-30144/? E/houdini\_hook: Unable to open libdvm\_houdini lib  
08-21 20:05:08.494 30144-30144/? E/houdini\_hook: Unable to open libdvm\_houdini lib  
08-21 20:05:08.494 30144-30144/? D/dalvikvm: Added shared lib [libnativehelper.so](http://libnativehelper.so) 0x0  
08-21 20:05:08.497 30144-30144/? D/dalvikvm: No JNI\_OnLoad found in [libnativehelper.so](http://libnativehelper.so) 0x0, skipping init  
08-21 20:05:08.533 30144-30144/? D/dalvikvm: Extra Options: not specified  
08-21 20:05:08.574 30144-30144/? D/dalvikvm: Note: class Landroid/app/ActivityManagerNative; has 179 unimplemented (abstract) methods  
08-21 20:05:08.848 30144-30144/? E/memtrack: Couldn’t load memtrack module (No such file or directory)  
08-21 20:05:08.849 30144-30144/? E/android.os.Debug: failed to load memtrack module: -2  
08-21 20:05:09.002 30144-30167/? I/dalvikvm: Total arena pages for JIT: 11  
08-21 20:05:09.003 30144-30167/? I/dalvikvm: Total arena pages for JIT: 12  
08-21 20:05:09.005 30144-30167/? I/dalvikvm: Total arena pages for JIT: 13  
08-21 20:05:09.008 30144-30167/? I/dalvikvm: Total arena pages for JIT: 14  
08-21 20:05:09.008 30144-30144/? D/AndroidRuntime: Calling main entry [com.android.commands.am.Am](http://com.android.commands.am.Am)  
08-21 20:05:09.015 30144-30167/? I/dalvikvm: Total arena pages for JIT: 15  
08-21 20:05:09.015 30144-30167/? I/dalvikvm: Total arena pages for JIT: 16  
08-21 20:05:09.019 30144-30167/? I/dalvikvm: Total arena pages for JIT: 17  
08-21 20:05:09.025 30144-30167/? I/dalvikvm: Total arena pages for JIT: 18  
08-21 20:05:09.026 30144-30167/? I/dalvikvm: Total arena pages for JIT: 19  
08-21 20:05:09.028 30144-30167/? I/dalvikvm: Total arena pages for JIT: 20  
08-21 20:05:09.102 30144-30144/? D/AndroidRuntime: Shutting down VM  
08-21 20:05:09.103 30144-30166/? D/jdwp: Got wake-up signal, bailing out of select  
08-21 20:05:09.103 30144-30166/? D/dalvikvm: Debugger has detached; object registry had 1 entries  
08-21 20:05:12.975 4554-4679/ W/System.err: net.sqlcipher.database.SQLiteException: error code 14: Could not open database  
I have also tried to put delay of 5 to 10 seconds to make sure that its not because of incomplete copy operation of db file. But no success.

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [August 22, 2017, 2:06pm UTC](https://discuss.zetetic.net/t/net-sqlcipher-database-sqliteexception-error-code-14-could-not-open-database/2323/2 "2017-08-22T14:06:43Z")

</div>

Hi @nilay\_singh

It appears you are overwriting the file stored in another location via an external application. Doing so would not be considered a safe operation as we do not know the state of the database when you attempt to copy it. If you can provide a repeatable example within the SQLCipher for Android [test suite](https://github.com/sqlcipher/sqlcipher-android-tests) we would be happy to look into this further.

---

<div class="post-metadata">

**Author:** ![hsvmks](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/hsvmks/32/662_2.png) [@hsvmks](https://discuss.zetetic.net/u/hsvmks)\
**Post date:** [August 22, 2017, 3:57pm UTC](https://discuss.zetetic.net/t/net-sqlcipher-database-sqliteexception-error-code-14-could-not-open-database/2323/3 "2017-08-22T15:57:12Z")

</div>

state of db is normal as it is under my application means all write permissions are there sometimes it work and all of a sudden it stops when you say Repeatable Example I did not get you

---

<div class="post-metadata">

**Author:** ![sjlombardo](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/sjlombardo/32/3_2.png) [@sjlombardo](https://discuss.zetetic.net/u/sjlombardo)\
**Post date:** [August 22, 2017, 7:09pm UTC](https://discuss.zetetic.net/t/net-sqlcipher-database-sqliteexception-error-code-14-could-not-open-database/2323/4 "2017-08-22T19:09:52Z")

</div>

@hsvmks - It would not be a safe operation to overwrite a SQLCipher database while it is in use. Furthermore, the scenario you mentioned is using an external process to manipulate the data. This isn’t really a supported scenario.

With regard to a repeatable example, we mean that you provide a complete standalone example that reliably demonstrates the problem in a test case, and then submit a pull request on GitHub.

That said, based on what we’re seeing here it doesn’t seem like a problem with SQLCipher itself.

---

<div class="post-metadata">

**Author:** ![hsvmks](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/hsvmks/32/662_2.png) [@hsvmks](https://discuss.zetetic.net/u/hsvmks)\
**Post date:** [August 23, 2017, 6:58am UTC](https://discuss.zetetic.net/t/net-sqlcipher-database-sqliteexception-error-code-14-could-not-open-database/2323/5 "2017-08-23T06:58:37Z")

</div>

net.sqlcipher.database.SQLiteException: error code 14: Could not open database this error are you sure it has nothing to do with SQLCipher I tried many thing copy db and then write permission and other things are correct means all open it just stops sometime

---

<div class="post-metadata">

**Author:** ![hsvmks](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/hsvmks/32/662_2.png) [@hsvmks](https://discuss.zetetic.net/u/hsvmks)\
**Post date:** [August 23, 2017, 7:35am UTC](https://discuss.zetetic.net/t/net-sqlcipher-database-sqliteexception-error-code-14-could-not-open-database/2323/6 "2017-08-23T07:35:46Z")

</div>

After debugging more I am seeing this error : calling error handler corrupt database detected .

And on this [https://github.com/sqlcipher/android-database-sqlcipher/blob/master/src/net/sqlcipher/database/SQLiteDatabase.java](https://github.com/sqlcipher/android-database-sqlcipher/blob/master/src/net/sqlcipher/database/SQLiteDatabase.java)

line number 537 I can see Calling error handler for corrupt database (detected) I want to know when and how this happens and what would be the best way to avoid this.

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [August 23, 2017, 2:36pm UTC](https://discuss.zetetic.net/t/net-sqlcipher-database-sqliteexception-error-code-14-could-not-open-database/2323/7 "2017-08-23T14:36:08Z")

</div>

Hi @hsvmks

The call to `onCorruption()` within the Java layer is typically due to catching the `SQLiteDatabaseCorruptionException`. An example of where this is called can be found within the [JNI layer](https://github.com/sqlcipher/android-database-sqlcipher/blob/master/jni/net_sqlcipher_database_SQLiteDatabase.cpp#L241) when the `PRAGMA integrity_check(1);` command fails. As @sjlombardo mentioned above, you are attempting an unsupported scenario where the state of the database is not known, thus it would not be considered safe. It is difficult to speculate the cause without a repeatable example.

---

<div class="post-metadata">

**Author:** ![sjlombardo](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/sjlombardo/32/3_2.png) [@sjlombardo](https://discuss.zetetic.net/u/sjlombardo)\
**Post date:** [August 23, 2017, 2:38pm UTC](https://discuss.zetetic.net/t/net-sqlcipher-database-sqliteexception-error-code-14-could-not-open-database/2323/8 "2017-08-23T14:38:45Z")

</div>

@hsvmks If we understand your process you are essentially overwriting the database every few seconds. SQLCipher is not a simple “flat file”, and opening a database does not decrypt it in its entirety. It is a complex file format that includes state information, version data, etc. You can’t just overwrite the file periodically. In effect you are probably corrupting the database every time you copy it like that, hence the corruption exception.
