示例#1
0
 public void Dispose()
 {
     _cleanupTimer?.Dispose();
     Commands?.Dispose();
     _db?.Close();
     _db?.Dispose();
 }
示例#2
0
 void IOpenDataSource.Close()
 {
     if (m_Transaction != null)
     {
         m_Transaction.Dispose();
     }
     m_Connection.Dispose();
 }
示例#3
0
        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();
                }
            }
        }
示例#4
0
 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();
     }
 }
示例#5
0
 /// <summary>
 /// 关闭数据库
 /// </summary>
 public void Close()
 {
     if (this.IsOpen)
     {
         dbc.Close();
     }
     if (dbc != null)
     {
         dbc.Dispose();
         dbc = null;
     }
     //throw new NotImplementedException();
 }
示例#6
0
        /// <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;
            }
        }
示例#7
0
        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);
        }
示例#8
0
        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);
            }
        }
示例#9
0
        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();
 }