Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLite: 'Unable to open the database file' exception with transaction with multiple commands
    text
    copied!<p>I have the following (simplified) code:</p> <pre><code>IDbConnection connection = new SQLiteConnection(GetConnectionString()); if (connection.State == ConnectionState.Closed) connection.Open(); using (IDbTransaction transaction = connection.BeginTransaction()) { using (IDbCommand cmd = transaction.Connection.CreateCommand()) { cmd.CommandText = "DELETE FROM Records2 WHERE ClientIndex = @ClientIndex"; AddParameter(cmd, "@ClientIndex", DbType.Int32, clientIndex); cmd.ExecuteNonQuery(); } using (IDbCommand cmd = transaction.Connection.CreateCommand()) { cmd.CommandText = "INSERT INTO Records2(ClientIndex, CandidateIndex, Name)"; cmd.CommandText += " VALUES(@ClientIndex, @CandidateIndex, @Name)"; AddParameter(cmd, "@ClientIndex", DbType.Int32, clientIndex); IDbDataParameter pIndex = AddParameter(cmd, "@CandidateIndex", DbType.Int32, null); IDbDataParameter pName = AddParameter(cmd, "@Name", DbType.AnsiString, null); int index = 0; foreach (Record record in records) { pIndex.Value = index++; pName.Value = record.Name; cmd.ExecuteNonQuery(); } } using (IDbCommand cmd = transaction.Connection.CreateCommand()) { cmd.CommandText = "UPDATE Records SET Status = @Status, UpdateDate = @UpdateDate WHERE ClientIndex = @ClientIndex"; AddParameter(cmd, "@ClientIndex", DbType.Int32, clientIndex); AddParameter(cmd, "@Status", DbType.Byte, status); AddParameter(cmd, "@UpdateDate", DbType.DateTime, DateTime.Now); cmd.ExecuteNonQuery(); } transaction.Commit(); } connection.Close(); </code></pre> <p>with:</p> <pre><code>private IDbDataParameter AddParameter(IDbCommand command, string paramName, DbType type, object value) { IDbDataParameter parameter = command.CreateParameter(); parameter.ParameterName = paramName; parameter.DbType = type; if (value != null) parameter.Value = value; else parameter.Value = DBNull.Value; command.Parameters.Add(parameter); return parameter; } </code></pre> <p>All the ExecuteNonQueries work without problems, except for the last one. On my machine (running xp) I get the following exception, but on other machines (running windows 7) it works without problems, with the same code and the same database file.</p> <pre><code>SQLiteException (0x80004005): Unable to open the database file System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt) +375 System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt) +199 System.Data.SQLite.SQLiteDataReader.NextResult() +226 System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave) +87 System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior) +38 System.Data.SQLite.SQLiteCommand.ExecuteNonQuery() +39 </code></pre> <p>I tried using JournalMode = Perist in the connection string and i excluded the directory containing the database file from my anti-virus, but nothing helps.</p> <p>I'm using the 3.5 Framework and my version of System.Data.SQLite is 1.0.66.0.</p> <p>Any Ideas ?</p> <p>Thanks in advance,</p> <p>Marc</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload