Esempio n. 1
0
 private void OpenConnection(FileInfo storeFile,
                             out IDbConnection newConnection)
 {
     lock (globalLock) {
         newConnection = Sqlite.GetDatabaseConnection(storeFile);
         try {
             using (var ver = newConnection.CreateCommand()) {
                 ver.CommandText = "PRAGMA user_version";
                 var currentVersion = (uint)(long)ver.ExecuteScalar();
                 if (!currentVersion.Equals(SCHEMA))
                 {
                     throw new ArgumentOutOfRangeException("SCHEMA");
                 }
             }
         }
         catch (Exception ex) {
             _logger.NoticeFormat(
                 "Recreating database, schema update. ({0})",
                 ex.Message
                 );
             Sqlite.ClearPool(newConnection);
             newConnection.Close();
             newConnection.Dispose();
             newConnection = null;
             for (var i = 0; i < 10; ++i)
             {
                 try {
                     GC.Collect();
                     storeFile.Delete();
                     break;
                 }
                 catch (IOException) {
                     Thread.Sleep(100);
                 }
             }
             newConnection = Sqlite.GetDatabaseConnection(storeFile);
         }
         using (var pragma = connection.CreateCommand()) {
             pragma.CommandText = "PRAGMA journal_size_limt = 33554432";
             pragma.ExecuteNonQuery();
             pragma.CommandText = "PRAGMA wal_autocheckpoint = 100";
             pragma.ExecuteNonQuery();
             pragma.CommandText = "PRAGMA wal_checkpoint(TRUNCATE)";
             pragma.ExecuteNonQuery();
         }
     }
 }
Esempio n. 2
0
 public void Dispose()
 {
     if (insert != null)
     {
         insert.Dispose();
     }
     if (select != null)
     {
         select.Dispose();
     }
     if (connection != null)
     {
         vacuumer.Remove(connection);
         Sqlite.ClearPool(connection);
         connection.Dispose();
     }
 }