public void Dispose() { _cleanupTimer?.Dispose(); Commands?.Dispose(); _db?.Close(); _db?.Dispose(); }
void IOpenDataSource.Close() { if (m_Transaction != null) { m_Transaction.Dispose(); } m_Connection.Dispose(); }
private void Connect() { if (_db == null) { var connectionString = _config.ConnectionString; _logger.LogTrace("Opening connection to SQLite database: " + "{ConnectionString}", connectionString); // First try to open an existing database if (!_config.MemoryOnly && System.IO.File.Exists(_config.CachePath)) { _logger.LogTrace("Found existing database at {CachePath}", _config.CachePath); var db = new DbConnection(_config.ConnectionString); db.Open(); if (CheckExistingDb(db)) { // Everything checks out, we can use this as our cache db _db = db; } else { if (db is not null) { _logger.LogTrace("Closing connection to SQLite database at {SqliteCacheDbPath}", _config.CachePath); db.Close(); db.Dispose(); } _logger.LogInformation("Deleting existing incompatible cache db file {CachePath}", _config.CachePath); System.IO.File.Delete(_config.CachePath); } } if (_db == null) { _db = new DbConnection(_config.ConnectionString); _db.Open(); Initialize(); } Commands = new DbCommandPool(_db, _logger); // Explicitly set default journal mode and fsync behavior using (var cmd = new DbCommand("PRAGMA journal_mode = WAL;", _db)) { cmd.ExecuteNonQuery(); } using (var cmd = new DbCommand("PRAGMA synchronous = NORMAL;", _db)) { cmd.ExecuteNonQuery(); } } }
public void Dispose() { _logger.LogTrace("Disposing SQLite cache database at {SqliteCacheDbPath}", _config.CachePath); _cleanupTimer?.Dispose(); Commands?.Dispose(); if (_db is not null) { _logger.LogTrace("Closing connection to SQLite database at {SqliteCacheDbPath}", _config.CachePath); _db.Close(); _db.Dispose(); } }
/// <summary> /// 关闭数据库 /// </summary> public void Close() { if (this.IsOpen) { dbc.Close(); } if (dbc != null) { dbc.Dispose(); dbc = null; } //throw new NotImplementedException(); }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> private void Dispose(bool disposing) { if (m_Disposed) { return; } if (disposing) { m_Transaction.Dispose(); m_Connection.Dispose(); if (m_LockToken != null) { m_LockToken.Dispose(); } m_Disposed = true; } }
public void Connection_works() { // Arrange. var connection = new Microsoft.Data.Sqlite.SqliteConnection("Data Source=:memory:"); // Act. connection.Open(); // Assert. Assert.AreEqual("main", connection.Database); Assert.AreEqual(System.Data.ConnectionState.Open, connection.State); // Act. connection.Dispose(); // Assert. Assert.AreEqual("main", connection.Database); Assert.AreEqual(System.Data.ConnectionState.Closed, connection.State); }
private void Connect() { if (_db == null) { var connectionString = _config.ConnectionString; _logger.LogTrace("Opening connection to SQLite database: " + "{ConnectionString}", connectionString); // First try to open an existing database if (!_config.MemoryOnly && System.IO.File.Exists(_config.CachePath)) { _logger.LogTrace("Found existing database at {CachePath}", _config.CachePath); var db = new DbConnection(_config.ConnectionString); db.Open(); if (CheckExistingDb(db)) { // Everything checks out, we can use this as our cache db _db = db; } else { db?.Dispose(); db?.Close(); _logger.LogInformation("Deleting existing incompatible cache db file {CachePath}", _config.CachePath); System.IO.File.Delete(_config.CachePath); } } if (_db == null) { _db = new DbConnection(_config.ConnectionString); _db.Open(); Initialize(); } Commands = new DbCommandPool(_db, _logger); } }
public void Dispose() { lock (_storageDirectory) { _storageDirectory.Remove(_file); } _conn.Close(); _conn.Dispose(); try { System.IO.File.Delete(_file); } catch { // file probably in use, try to delete in 5 seconds var thread = new Thread(() => { Thread.Sleep(5000); try { System.IO.File.Delete(_file); } catch { } }); thread.Start(); } if (Disposing != null) { Disposing(); Disposing = null; } }
public void Dispose() { connection.Dispose(); }