Fix: Don't activate/deactive objects when we don't have a database connection.
Add missing lock.