lundi 12 octobre 2015

How to solve the SQLite "Database is locked" in C#?

When I update some data, sometimes it throws a exception: Database is locked. The code below:

    public int DisableSalesBySalesID(string SalesID)
    {
        int count = 0;
        try
        {
            using (SQLiteConnection conn = new SQLiteConnection(ConnectionString))
            {
                conn.Open();
                string sql = @"update SalesMaster set Disabled = '1' where SalesID=@SalesID";
                using (SQLiteCommand cmd = new SQLiteCommand(sql, conn))
                {

                    cmd.Parameters.Add(new SQLiteParameter("@SalesID", SalesID));
                    count = cmd.ExecuteNonQuery();
                }
            }
        }
        catch (Exception ex)
        {
        }
        return count;
    }

And, it depends on SalesID. Some SalesID will be ok ,but the others will make the exception. Why?

Aucun commentaire:

Enregistrer un commentaire