Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like you failed to link the command with the transaction you've created. Instead of:</p> <pre><code>using (SQLiteCommand command = conn.CreateCommand()) </code></pre> <p>You should use:</p> <pre><code>using (SQLiteCommand command = new SQLiteCommand("&lt;INSERT statement here&gt;", conn, trans)) </code></pre> <p>Or you can set its Transaction property after its construction.</p> <p>While we are at it - your handling of failures is incorrect:</p> <p>The command's ExecuteNonQuery method can also fail and you are not really protected. You should change the code to something like:</p> <pre><code> public void Commit() { using (SQLiteConnection conn = new SQLiteConnection(this.connString)) { conn.Open(); SQLiteTransaction trans = conn.BeginTransaction(); try { using (SQLiteCommand command = conn.CreateCommand()) { command.Transaction = trans; // Now the command is linked to the transaction and don't try to create a new one (which is probably why your database gets locked) command.CommandText = "INSERT OR IGNORE INTO [MY_TABLE] (col1, col2) VALUES (?,?)"; command.Parameters.Add(this.col1Param); command.Parameters.Add(this.col2Param); foreach (Data o in this.dataTemp) { this.col1Param.Value = o.Col1Prop; this. col2Param.Value = o.Col2Prop; command.ExecuteNonQuery(); } } trans.Commit(); } catch (SQLiteException ex) { // You need to rollback in case something wrong happened in command.ExecuteNonQuery() ... trans.Rollback(); throw; } } } </code></pre> <p>Another thing is that you don't need to cache anything in memory. You can depend on SQLite journaling mechanism for storing incomplete transaction state.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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