Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've investigated it by myself:</p> <p>I created a sample SQLite database <code>c:\123.db</code> with one table <code>Categories</code> containing two fields: <code>ID</code> (uniqueidentifier) and <code>Name</code> (nvarchar).</p> <p>I then wrote some multi-thread code to emulate multiple write access to the database (don't forget to add a <code>System.Data.SQLite</code> reference to your project if you use this code):</p> <pre><code>using System; using System.Data.SQLite; using System.Threading.Tasks; namespace SQLiteTest { class Program { static void Main(string[] args) { var tasks = new Task[100]; for (int i = 0; i &lt; 100; i++) { tasks[i] = new Task(new Program().WriteToDB); tasks[i].Start(); } foreach (var task in tasks) task.Wait(); } public void WriteToDB() { try { using (SQLiteConnection myconnection = new SQLiteConnection(@"Data Source=c:\123.db")) { myconnection.Open(); using (SQLiteTransaction mytransaction = myconnection.BeginTransaction()) { using (SQLiteCommand mycommand = new SQLiteCommand(myconnection)) { Guid id = Guid.NewGuid(); mycommand.CommandText = "INSERT INTO Categories(ID, Name) VALUES ('" + id.ToString() + "', '111')"; mycommand.ExecuteNonQuery(); mycommand.CommandText = "UPDATE Categories SET Name='222' WHERE ID='" + id.ToString() + "'"; mycommand.ExecuteNonQuery(); mycommand.CommandText = "DELETE FROM Categories WHERE ID='" + id.ToString() + "'"; mycommand.ExecuteNonQuery(); } mytransaction.Commit(); } } } catch (SQLiteException ex) { if (ex.ReturnCode == SQLiteErrorCode.Busy) Console.WriteLine("Database is locked by another process!"); } } } } </code></pre> <p>The result on my Core2Duo E7500 is that Exception is never raised!</p> <p>Looks like SQLite is optimised enough for my needs (locking/unlocking is really fast and normally only takes a few milliseconds as <a href="http://www.sqlite.org/faq.html#q5" rel="nofollow noreferrer">SQLite FAQ</a> tells us) - Great!</p> <p>Note that there is no need to retrieve an integer ErrorCode for an <code>SQLiteException</code> - you can use a special enum <code>ReturnCode</code> field instead. All codes are described <a href="http://www.sqlite.org/c3ref/c_abort.html" rel="nofollow noreferrer">here</a>.</p> <p>Hope this information will help somebody.</p>
 

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