Add try finally to close connection safety