Is it possible that the file is in the process of being closed (I.e. SQLLite doesn't release it immediately)?
You could try putting the db close in a delay loop, (maybe one second between each attempt), and only throwing the exception after a few (5 or so) iterations through the loop.