Fixes issue with db connection not being closed after inserting data