Ensure disposing database object

Reported by Tomoatsu Shimada. Thanks!!!