Fix #8275
Merge pull request #718 from ddanielvaz/fix-8275

cleanup temporary database after write check (fixes #8275)