Fixed #21553 -- Ensured unusable database connections get closed.