# Trouble using sqlcipher\_export() from .NET

**URL:** <https://discuss.zetetic.net/t/trouble-using-sqlcipher-export-from-net/6732>\
**Category:** Issues\
**Created:** [November 8, 2024, 8:20pm UTC](https://discuss.zetetic.net/t/trouble-using-sqlcipher-export-from-net/6732 "2024-11-08T20:20:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RayHayes](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@RayHayes](https://discuss.zetetic.net/u/RayHayes)\
**Post date:** [November 8, 2024, 8:20pm UTC](https://discuss.zetetic.net/t/trouble-using-sqlcipher-export-from-net/6732/1 "2024-11-08T20:20:02Z")

</div>

I’ve followed the guidance for a few days now trying to debug where my code is incorrect. I get the 26 error after it runs trying to convert a plaintext to encrypted. Any pointers?

This code executes and used to work. Something changed either in the libraries being used or perhaps something else. If I create a brand new database with encryption, it works fine. If this code is called to convert a previous version, the database is unuseable after the conversion.

```
                try
                {
                    if (_con == null)
                        throw new InvalidDataException("No database connection exists");

                    using var command = _con.CreateCommand();
                    command.CommandText = @"ATTACH DATABASE '" + dbEncrypted + "' AS encrypted KEY '" + encryptionKey + "'";
                    command.ExecuteNonQuery();
                    TracingAndLogging.TraceInformation(command.CommandText);
                    TracingAndLogging.TraceInformation("AddEncryption: Created and attached to the encrypted database");

                    command.CommandText = @"SELECT sqlcipher_export('encrypted');";
                    int converted = command.ExecuteNonQuery();
                    TracingAndLogging.TraceInformation(command.CommandText);
                    TracingAndLogging.TraceInformation("AddEncryption: Export into the encrypted database: " + converted.ToString());

                    TracingAndLogging.TraceInformation("AddEncryption: Exporting complete");

                    command.CommandText = @"DETACH DATABASE encrypted;";
                    command.ExecuteNonQuery();
                    TracingAndLogging.TraceInformation(command.CommandText);
                    TracingAndLogging.TraceInformation("AddEncryption: Detached from the encrypted database");
                }
                catch (Exception ex)
                {
                    TracingAndLogging.TraceWarning("AddEncryption: " +
                        String.Format(Properties.Resources.Trace_15, ex.Message));
                }

                CloseDB();

```

---

<div class="post-metadata">

**Author:** ![RayHayes](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@RayHayes](https://discuss.zetetic.net/u/RayHayes)\
**Post date:** [November 10, 2024, 6:19am UTC](https://discuss.zetetic.net/t/trouble-using-sqlcipher-export-from-net/6732/2 "2024-11-10T06:19:26Z")

</div>

Figured it out. The format of the connection string is very specific and once I removed the addition of the SqliteConnectionStringBuilder class and went back to the original custom class I was using, it started working again.
