Why do you set database only when it is closed?