Thanks Stephen, I'm afraid I'm a little confused now though..
I had been using the SQLiteConnection.SetPassword("password") before
opening the connection when creating and opening a database. I know
notice that this function was in the old System.Data.Sqlite.dll, so is
this function now obsolete?
This is what I had:
using (SQLiteConnection conn = new
SQLiteConnection(_connectionString))
{
conn.SetPassword(_password);
conn.Open();
if (createNew)
{
using (SQLiteCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "CREATE TABLE \"Test\"(\"X\" INTEGER);";
cmd.ExecuteNonQuery();
}
}
...
}
I've changed it to:
using (SQLiteConnection conn = new
SQLiteConnection(_connectionString))
{
conn.Open();
using (SQLiteCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "PRAGMA key = '@Password'; PRAGMA
cipher_use_hmac = OFF;";
cmd.Parameters.Add(new SQLiteParameter("@Password",
_password));
cmd.ExecuteNonQuery();
}
if (createNew)
{
using (SQLiteCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "CREATE TABLE \"Test\"(\"X\" INTEGER);";
cmd.ExecuteNonQuery();
}
}
...
}
Here the database is created correctly, but when I try to open it
again I get the same error, even on the same machine that created it.
File opened that is not a database file
file is encrypted or is not a database
at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String
strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain)
at System.Data.SQLite.SQLiteCommand.BuildNextCommand()
at System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index)
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd,
CommandBehavior behave)
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior
behavior)
at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
at System.Data.SQLite.SQLiteConnection.Open()