Sqlite-net: Database Locked Error

Created on 20 Sep 2018  路  5Comments  路  Source: praeclarum/sqlite-net

I have upgraded from 1.4.118 to 1.5.231 and whenever I try to execute a scalar on an asynchronous connection, I receive an error that the database is locked. I had do downgrade to 1.4.118 and the issue is no longer present. What changed? I'm using this for a Xamarin forms project in conjunction with MVVMCross 6.2. Here is the simple method I call:

public async Task TableExists()
{
try
{
var command =
$"SELECT count(tbl_name) FROM sqlite_master WHERE type = 'table' AND name = '{typeof(T).Name}'";
var count = await DbAsynchronousConnection.ExecuteScalarAsync(command).ConfigureAwait(false);

            return count > 0;
        }
        catch (SQLiteException sqLiteException)
        {
            throw;
            //todo: handle the exception
        }
    }
Bug

All 5 comments

What is this DbAsynchronousConnection you are using?
Try creating a new instance of a SQLiteAsyncConnection and using that for the ExecuteScalarAsync command. I think you use a single instance of SQLiteAsyncConnection for multiple queries and that is the source of your problems.
Moreover, check if you have storage permission acquired before running commands on the database.

I looked it a bit thorougher and I have found that it could also be a known bug: #740

First time i works, but next time i open my app, I also get Database Locked.
no problems in 1.4.118 :-)

This should be fixed in the 1.6-beta. Please let me know if it is not!

@praeclarum any updates on the 1.6 release ETA?
I'm seeing this lock issue on < iOS 12

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yaliashkevich picture yaliashkevich  路  3Comments

M-Curtis picture M-Curtis  路  3Comments

pha3z picture pha3z  路  4Comments

Freddixx picture Freddixx  路  4Comments

xleon picture xleon  路  3Comments