close database when the callback is executed