1
votes

It seems the SQLite Database is locked when I do a delete operation as below:

And I need to delete two times in order to refresh. What is the normal way to delete without any locking by the Sqlite Database?

    var ThisTrans = await db.QueryAsync<TransactionLine>("Select * From TransactionLine Where  Tid = '" + PassInTransId + "'");
    foreach (var line in ThisTrans)
    {
        var intDelStatus = db.DeleteAsync(line);
    }
    //- can  I use this to close Connection?? but it does not work!
    db = null;


--- solution

private async Task<bool> DelTransactionLine(int PassInTransId)
 {


 //--1-- delete the selected transaction line
var ThisTrans = await db.QueryAsync<TransactionLine>("Select * From TransactionLine Where  Tid = '" + PassInTransId + "'");

   foreach (var line in ThisTrans)
  {
    var intDelStatus = await db.DeleteAsync(line);
   }

 return true;


 }







1
I don't know how SQLite works, but I have a couple of ideas. Could it be that the DeleteAsync is not done when you call it again? Is there a sync Delete? Try with a Thread.Sleep right after calling the DeleteAsync to see if that's itsebagomez

1 Answers

1
votes

Can you do something like:

var ThisTrans = await db.QueryAsync<TransactionLine>("Select * From TransactionLine    Where  Tid = '" + PassInTransId + "'");
foreach (var line in ThisTrans)
{
    var intDelStatus = await db.DeleteAsync(line);
}

To await the delete operation returning before you try and delete the next one?