Share common database close code