1

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 it Commented Jan 28, 2014 at 15:55

1 Answer 1

1

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?

Sign up to request clarification or add additional context in comments.

2 Comments

I need to use Task<t> for this Delete function. Call this Task<t> base function will solve my problem.
Forget to add : Use Function base on Task<> and your suggestion of await keyword. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.