title: Mono SQLite fails to open database
body: <p>I have written a simple Mono C# application for writing to an SQLite database using the Mono implementation present in the <code>Mono.Data.Sqlite</code> package:</p>
  
  <pre><code>using System;
  using Mono.Data.Sqlite;
  
  class MainClass
  {
      public static void Main (string[] args)
      {
          using (var dbConnection = new SqliteConnection (@"Data Source=/var/log/gmblog;Version=3;"))
          {
              dbConnection.Open();
  
              string sql = @"INSERT INTO ""queue"" (""data"") VALUES(""Test"")";
              using (var insertCommand = new SqliteCommand (sql, dbConnection))
              {
                  insertCommand.ExecuteNonQuery();
              }
          }
      }
  }
  </code></pre>
  
  <p>This works fine until I do an insert from another application such as <code>sqlite3</code> and keeps this application running:</p>
  
  <pre><code>sqlite&gt; insert into queue ("data") VALUES("test2");
  </code></pre>
  
  <p>Now the C# program hangs until it gives the following error:</p>
  
  <pre><code>Unhandled Exception: Mono.Data.Sqlite.SqliteException: The database file is locked
  </code></pre>
  
  <p>I don't have any problems writing to the table from other instances of <code>sqlite3</code> or from a C++ application I created.</p>
  
  <p>If I close the <code>sqlite3</code> instance then the C# application works again.</p>
  
  <p>Doing a <code>lsof /var/log/gmblog</code> shows that <code>sqlite3</code> has obtained a reader lock after performing the INSERT:</p>
  
  <pre><code>sqlite3 15578  cup    3ur  REG   8,17    13312 4988505 /var/log/gmblog
  </code></pre>
  
  <p>Before the INSERT it didn't have this lock:</p>
  
  <pre><code>sqlite3 15578  cup    3u   REG   8,17    13312 4988505 /var/log/gmblog
  </code></pre>
  
  <p>But as I pointed out other applications do not have any problems written to the table while other applications are using the database.</p>
  
  <p>Any ideas on what is wrong with my C# code? Is it a bug in the Mono implementation of SQLite?</p>
  
  <p><strong>Update 25/11</strong></p>
  
  <p>Note that it's the <code>dbConnection.Open();</code> which results in the database locked error, not the <code>insertCommand.ExecuteNonQuery();</code>. I.e. the following code doesn't work either:</p>
  
  <pre><code>using System;
  using Mono.Data.Sqlite;
  
  class MainClass
  {
      public static void Main (string[] args)
      {
          using (var dbConnection = new SqliteConnection (@"Data Source=/var/log/gmblog;Version=3;"))
          {
              dbConnection.Open();
          }
      }
  }
  </code></pre>