Hi.
I've read the whole thread and used everything as described, but i'm still not able to open a decrypted database. So far System.Data.SQLite worked perfectly with unencrypted databases.
I'm currently testing for perfomance and the general usefulness of SQLite in my private applications. I have encrypted the test database as described by setting the password via System.Data.SQLite. The resulting encrypted database could be opened and manipulated in every SQLite software i could get my hand on, so the database is in order.
- I'm using Visual Studio 2005 Professional, running on Windows XP SP2.
- The Project has a reference to the 1.0.49.0 System.Data.SQLite.dll.
- As i previously blamed the connection faults to a wrongly formed connection string i used the provided SQLiteConnectionStringBuilder class to form the connection string. The resulting string is
Data Source = D:\Programming\c#\Test\DataEnc2.db3;Password=mypassword
which is, as far as i can tell correct.
The wrapper class i've written builds the connection in the constructor and stores it in the field _connection, the function performing the query on the database opens and closes the connection to the database as needed (code follows below).
That worked perfectly with an unencrypted database. As soon as i switched to a test using my encrypted database, calling _connection.open() threw an exception giving the error code NotADatabase and the dreaded error message:
File opened that is not a database file
file is encrypted or is not a database
I hope that was enough information. I simply don't know what i'm doing wrong.
Schuck
Here are the class constructor and the query function used:
/// <summary>
/// This function does the actual initialization.
/// </summary>
/// <param name="query">The initial query</param>
protected virtual void ConstructorCore(string query)
{
_query = query;
_affected = 0;
SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder();
//Testing with unencrypted Database - passed
//builder.DataSource = @"D:\Programming\c#\Test\Data.db3";
//This is the same Database only encrypted.
builder.DataSource = @"D:\Programming\c#\Test\DataEnc2.db3";
builder.Password = @"mypassword";
// Storing connection
_connection = new SQLiteConnection(builder.ConnectionString);
// preparing adapter
_adapter = new SQLiteDataAdapter();
// preparing Result Table.
_table = new DataTable();
}
/// <summary>
/// Executes the stored query on the Database.
/// </summary>
protected virtual void PerformQuery()
{
// Empty query is empty
if (_query == String.Empty)
return;
SQLiteCommand query = new SQLiteCommand(_query, _connection);
try
{
// Connecting to Database.
_connection.Open();
_table.Clear();
_table.Columns.Clear();
_adapter.SelectCommand = query;
_adapter.Fill(_table);
}
catch (SQLiteException e)
{
MessageBox.Show(e.Message + "\nConnection String: " + _connection.ConnectionString, "Query Error: " + e.ErrorCode.ToString());
}
finally
{
// Disconnecting from Database
_connection.Close();
}
// Announce Affected Rows:
_affected = _table.Rows.Count;
OnPropertyChange("AffectedDatasets");
}