# Issue attaching DBs Android

**URL:** <https://discuss.zetetic.net/t/issue-attaching-dbs-android/6226>\
**Category:** Issues\
**Created:** [January 29, 2024, 5:27pm UTC](https://discuss.zetetic.net/t/issue-attaching-dbs-android/6226 "2024-01-29T17:27:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivaylo\_Todorov](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/ivaylo_todorov/32/2140_2.png) [@Ivaylo\_Todorov](https://discuss.zetetic.net/u/Ivaylo_Todorov)\
**Post date:** [January 29, 2024, 5:27pm UTC](https://discuss.zetetic.net/t/issue-attaching-dbs-android/6226/1 "2024-01-29T17:27:18Z")

</div>

Hello team,

We’ve been using SQLCipher for years in our project and are recently migrating from version 4.5.4 to 4.5.5/6. The described below issue is reproducible in both 4.5.5 and 4.5.6 versions.  
We have some data split between 2 DB files, let’s call them “principal” and “details”.  
Both DBs are encrypted and created with the same KEY. This is during clean app installation - so, no DBs, no migrations, no version conflicts.  
After creating and opening the DBs we attach them using the following command, having the key preformatted to hexadecimal representation as expected:

```java
principalDb.execSQL("attach \"" + detailsDb.getPath() + "\" as DetailsDatabase KEY \"" + new String(dbKey.getCharKey()) + "\"");

```

At this point, we have both DBs created, opened, accessible, writable, and as mentioned created with the same KEY - those statements are confirmed.  
This was working without any issues up to version 4.5.4.  
Now, I get the following error:

```java
(26) statement aborts at 4: [attach "/data/user/0/com.our.app/databases/details.db" as DetailsDatabase KEY "x'388B37296AD10BEF56C8B199566C55CB1AAF8B50853DA18003C2109FE8D0A7B3'"] file is not a database

```

This KEY is randomly generated once during the app start and is the same as the one used to create both DBs.

I also tried using the approach without explicitly passing the KEY, so it uses the KEY of the “principal” DB, which in this case is the same… it results in the same error!

A colleague of mine said that she tried the same DB attachment operation with Plain Text (not encrypted) DBs - with the same result.

Please advise,  
Thanks beforehand!

---

<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:** [January 29, 2024, 5:50pm UTC](https://discuss.zetetic.net/t/issue-attaching-dbs-android/6226/2 "2024-01-29T17:50:00Z")

</div>

Hi @Ivaylo_Todorov,

Are you able to reproduce this? If so, when this occurs in development, can you please pull the database file off the device to see if you are able to access the SQLCipher database file from the command line interface on a host computer?

---

<div class="post-metadata">

**Author:** ![Ivaylo\_Todorov](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/ivaylo_todorov/32/2140_2.png) [@Ivaylo\_Todorov](https://discuss.zetetic.net/u/Ivaylo_Todorov)\
**Post date:** [January 30, 2024, 9:24am UTC](https://discuss.zetetic.net/t/issue-attaching-dbs-android/6226/3 "2024-01-30T09:24:32Z")

</div>

Yes, this is 100% reproducible, on real devices and Emulators.  
Yes, the DB file is there and accessible - I was able to download it using same path.

---

<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:** [January 30, 2024, 2:32pm UTC](https://discuss.zetetic.net/t/issue-attaching-dbs-android/6226/4 "2024-01-30T14:32:31Z")

</div>

Hi @Ivaylo_Todorov,

Just for clarification, were you able to open the database file with the raw key using the SQLCipher command line shell? If so, can you reach out to us at [support@zetetic.net](mailto:support@zetetic.net) with the sample database file and the raw key for further review?

---

<div class="post-metadata">

**Author:** ![Ivaylo\_Todorov](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/ivaylo_todorov/32/2140_2.png) [@Ivaylo\_Todorov](https://discuss.zetetic.net/u/Ivaylo_Todorov)\
**Post date:** [January 30, 2024, 5:30pm UTC](https://discuss.zetetic.net/t/issue-attaching-dbs-android/6226/5 "2024-01-30T17:30:14Z")

</div>

This last helped me to find the issue… and it’s on our side.  
A different key representation, of the same key, was provided when creating the OpenHelper.  
Thanks for your assistance 🙂

---

<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:** [January 30, 2024, 9:59pm UTC](https://discuss.zetetic.net/t/issue-attaching-dbs-android/6226/6 "2024-01-30T21:59:54Z")

</div>

Hi @Ivaylo_Todorov,

Excellent, glad to hear you were able to isolate the issue!
