Augment die function so that aceepts a connection and closes the database when an error occurs.