# Android. sqlcipher\_export - unable to open database

**URL:** <https://discuss.zetetic.net/t/android-sqlcipher-export-unable-to-open-database/659>\
**Category:** Issues\
**Created:** [July 12, 2015, 1:09pm UTC](https://discuss.zetetic.net/t/android-sqlcipher-export-unable-to-open-database/659 "2015-07-12T13:09:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexTereschuk](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@AlexTereschuk](https://discuss.zetetic.net/u/AlexTereschuk)\
**Post date:** [July 12, 2015, 1:09pm UTC](https://discuss.zetetic.net/t/android-sqlcipher-export-unable-to-open-database/659/1 "2015-07-12T13:09:20Z")

</div>

Hi everyone. I have a problem when trying to export my database. I have exeption:  
net.sqlcipher.database.SQLiteException: unable to open database

My code:

```
String dbPath = context.getDatabasePath(DATABASE_NAME).getPath();

        File dbPathFile = new File(dbPath);
        if (!dbPathFile.exists())
            dbPathFile.getParentFile().mkdirs();

        SQLiteDatabase database = SQLiteDatabase.openDatabase(dbPath, password, null, 0);
        database.rawExecSQL("PRAGMA key = '" + password + "'");
        database.rawExecSQL("ATTACH DATABASE '" + DATABASE_NAME + "' AS SQLChiperSample KEY ''");
        database.rawExecSQL("SELECT sqlcipher_export('SQLChiperSample')");
        database.rawExecSQL("DETACH DATABASE SQLChiperSample");

```

The error appears on this line:

```
 database.rawExecSQL("ATTACH DATABASE '" + DATABASE_NAME + "' AS SQLChiperSample KEY ''");

```

What’s the error?

---

<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:** [July 13, 2015, 1:34pm UTC](https://discuss.zetetic.net/t/android-sqlcipher-export-unable-to-open-database/659/2 "2015-07-13T13:34:54Z")

</div>

Hello @AlexTereschuk

There are a couple of items here that need to be adjusted. First, you do not need to perform a `PRAGMA key …;` operation as that is handled for you in the line above when you provide the password to the database connection. Next, you already have a connection to `DATABASE_NAME` open, referenced by the `database` variable, if you want to attach another database, you would need to use an alternative name to attach to for performing your export. As an example, please take a look at example #2 in the documentation [here](https://www.zetetic.net/sqlcipher/sqlcipher-api/#sqlcipher_export).
