# Why I can't attach an encrypted database to an encrypted database

**URL:** <https://discuss.zetetic.net/t/why-i-cant-attach-an-encrypted-database-to-an-encrypted-database/6429>\
**Category:** SQLCipher\
**Created:** [May 2, 2024, 1:19pm UTC](https://discuss.zetetic.net/t/why-i-cant-attach-an-encrypted-database-to-an-encrypted-database/6429 "2024-05-02T13:19:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackie](https://avatars.discourse-cdn.com/v4/letter/j/f07891/32.png) [@jackie](https://discuss.zetetic.net/u/jackie)\
**Post date:** [May 2, 2024, 1:19pm UTC](https://discuss.zetetic.net/t/why-i-cant-attach-an-encrypted-database-to-an-encrypted-database/6429/1 "2024-05-02T13:19:54Z")

</div>

There are 2 encrypted sqlite3 database: test.db and abc.db. The password of both database are “123456”. Now I want to attach abc.db to test.db. But the return value is 26. Why?

sqlite3\_open(“D:\test.db", &db);  
sqlite3\_key(db, ”123456“, 6);  
sqlite3\_exec(db, (const char\*)“PRAGMA cipher\_use\_hmac = off”, NULL, NULL, NULL);  
sqlite3\_exec(db, (const char\*)“PRAGMA cipher\_page\_size = 1024”, NULL, NULL, NULL);  
sqlite3\_exec(db, (const char\*)“PRAGMA kdf\_iter = 4000”, NULL, NULL, NULL);  
char chAttach[500];  
sprintf\_s(chAttach,500,“ATTACH DATABASE ‘D:\abc.db’ AS ‘db2’ KEY ‘%s’”,“123456”);  
int nRet=sqlite3\_exec(db, (const char\*)chAttach, NULL, NULL, NULL);  
if ( nRet!= SQLITE\_OK) //nRet is 26  
{  
MessageBox(NULL,“Failure”,“”,MB\_OK);  
}

If I attach a unencrypted database to a unencrypted database. It will work. Why I can’t attach an encrypted database to an encrypted database?

---

<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:** [May 15, 2024, 4:26pm UTC](https://discuss.zetetic.net/t/why-i-cant-attach-an-encrypted-database-to-an-encrypted-database/6429/2 "2024-05-15T16:26:36Z")

</div>

@jackie - is the abc.db using non-standard settings like test.db? If so, you’d need to account for those when attaching the database.
