title: Performing a lot of SQlite queries in Xamarin.Android fails
body: <p>I'm working on an app that gets some data from a webservice. The program is written in C# with Xamarin Studio.</p>
  
  <p>The app has a local SQLite database stored in a file. I have created a seperate Database class to simplify the inner workings of the database (such as opening and closing the connection, etc.). Here's a relevant snippet of this class:</p>
  
  <pre><code>public static SqliteConnection connect(){
              string documentPath = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);
              try {
                  return new SqliteConnection (string.Format ("Data Source={0};Version=3;", documentPath + "Database.db"));
              } catch {
                  Console.WriteLine ("New DB created!");
                  SqliteConnection.CreateFile (documentPath + "Database.db");
                  return new SqliteConnection (string.Format ("Data Source={0};Version=3;", documentPath + "Database.db"));
              }
          }
  
  public static void doQuery(string query){
              //Console.WriteLine ("Performing no-return query: " + query);
              using(var conn = connect()){
                  conn.Open ();
                  using(var cmd = conn.CreateCommand ()){
                      var trans = conn.BeginTransaction ();
                      cmd.CommandText = query;
                      cmd.CommandType = CommandType.Text;
                      cmd.Transaction = trans;
                      cmd.ExecuteNonQuery ();
                      trans.Commit ();
                  }
              }
          }
  
  public static DataTable getQueryResult(string query){
      //Console.WriteLine ("Performing return query: " + query);
      using (var conn = connect()) {
          conn.Open ();
          using (var cmd = conn.CreateCommand ()) {
              cmd.CommandText = query;
              cmd.CommandType = CommandType.Text;
              SqliteDataReader rdr = cmd.ExecuteReader ();
              DataTable dt = new DataTable ();
              dt.Load (rdr);
              return dt;
          }
      }
     }
  </code></pre>
  
  <p>After performing approx. 1900 queries, I get this error:</p>
  
  <pre><code>[mono] Unhandled Exception:
  [mono] Mono.Data.Sqlite.SqliteException: Unable to open the database file
  [mono] unable to open database file
  [mono]   at Mono.Data.Sqlite.SQLite3.Reset (Mono.Data.Sqlite.SqliteStatement stmt) [0x00000] in &lt;filename unknown&gt;:0 
  [mono]   at Mono.Data.Sqlite.SQLite3.Step (Mono.Data.Sqlite.SqliteStatement stmt) [0x00000] in &lt;filename unknown&gt;:0 
  [mono]   at Mono.Data.Sqlite.SqliteDataReader.NextResult () [0x00000] in &lt;filename unknown&gt;:0 
  [mono]   at Mono.Data.Sqlite.SqliteDataReader..ctor (Mono.Data.Sqlite.SqliteCommand cmd, CommandBehavior behave) [0x00000] in &lt;filename unknown&gt;:0 
  [mono]   at (wrapper remoting-invoke-with-check) Mono.Data.Sqlite.SqliteDataReader:.ctor (Mono.Data.Sqlite.SqliteCommand,System.Data.CommandBehavior)
  [mono]   at Mono.Data.Sqlite.SqliteCommand.ExecuteReader (CommandBehavior behavior) [0x00000] in &lt;filename unknown&gt;:0 
  [mono]   at Mono.Data.Sqlite.SqliteCommand.ExecuteNonQuery () [0x00000] in &lt;filename unknown&gt;:0 
  [mono]   at Mono.Data.Sqlite.SqliteTransaction..ctor (Mono.Data.Sqlite.SqliteConnection connection, Boolean deferred
  </code></pre>
  
  <p>This error is thrown at the "var trans = conn.BeginTransaction ();" line inside the doQuery method.</p>
  
  <p>I think it's something related to not disposing the objects, but since I'm using using() for the connections and commands, I don't see why...</p>
  
  <p>I hope someone can help me!</p>
  
  <p>DebboR</p>