Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLite Database Locked exception
    primarykey
    data
    text
    <p>I am getting <strong>Database is locked</strong> exception from <strong>SQLite</strong> for some queries only. </p> <p>Below is my code: When I execute any select statement it works fine.<br> When I am executing any write statement on <code>Jobs</code> Table it also works fine. </p> <p>This works fine: </p> <pre><code>ExecuteNonQuery("DELETE FROM Jobs WHERE id=1"); </code></pre> <p>But the same way if I am executing queries for <code>Employees</code> table it is throwing an exception that <strong>database is locked</strong>.<br> This throws Exception:</p> <pre><code>ExecuteNonQuery("DELETE FROM Employees WHERE id=1"); </code></pre> <p>Below are my functions:</p> <pre><code>public bool OpenConnection() { if (Con == null) { Con = new SQLiteConnection(ConnectionString); } if (Con.State == ConnectionState.Closed) { Con.Open(); //Cmd = new SQLiteCommand("PRAGMA FOREIGN_KEYS=ON", Con); //Cmd.ExecuteNonQuery(); //Cmd.Dispose(); //Cmd=null; return true; } if (IsConnectionBusy()) { Msg.Log(new Exception("Connection busy")); } return false; } public Boolean CloseConnection() { if (Con != null &amp;&amp; Con.State == ConnectionState.Open) { if (Cmd != null) Cmd.Dispose(); Cmd = null; Con.Close(); return true; } return false; } public Boolean ExecuteNonQuery(string sql) { if (sql == null) return false; try { if (!OpenConnection()) return false; else { //Tx = Con.BeginTransaction(IsolationLevel.ReadCommitted); Cmd = new SQLiteCommand(sql, Con); Cmd.ExecuteNonQuery(); //Tx.Commit(); return true; } } catch (Exception exception) { //Tx.Rollback(); Msg.Log(exception); return false; } finally { CloseConnection(); } } </code></pre> <p>This is the Exception: At line 103 : <code>Cmd.ExecuteNonQuery();</code></p> <blockquote> <p>Exception Found: Type: System.Data.SQLite.SQLiteException Message: database is locked database is locked Source: System.Data.SQLite</p> <p>Stacktrace: at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt) at System.Data.SQLite.SQLiteDataReader.NextResult() at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave) at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior) at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery() at TimeSheet6.DbOp.ExecuteNonQuery(String sql) in d:\Projects\C# Applications\Completed Projects\TimeSheet6\TimeSheet6\DbOp.cs:line 103</p> </blockquote>
    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.
 

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