static void Close(ref sqlite3 db)
 {
     if (db == null)
     {
         return;
     }
     try
     {
         // Close any open statements, otherwise the
         // sqlite connection won't actually close.
         sqlite3_stmt next = null;
         while ((next = db.next_stmt(next)) != null)
         {
             next.Dispose();
         }
         db.close();
         Log.I(Tag, "db connection {0} closed", db);
     }
     catch (KeyNotFoundException ex)
     {
         // Appears to be a bug in sqlite3.find_stmt. Concurrency issue in static dictionary?
         // Assuming we're done.
         Log.W(Tag, "Abandoning database close.", ex);
     }
     catch (ugly.sqlite3_exception ex)
     {
         Log.E(Tag, "Retrying database close.", ex);
         // Assuming a basic retry fixes this.
         Thread.Sleep(5000);
         db.close();
     }
     GC.Collect();
     GC.WaitForPendingFinalizers();
     try
     {
         db.Dispose();
     }
     catch (Exception ex)
     {
         Log.E(Tag, "Error while closing database.", ex);
     }
     finally
     {
         db = null;
     }
 }
 public void Close()
 {
     db.Dispose();
     db = null;
 }