Manually close db connections inside management scripts.

fix #557