1

I'm doing some integration tests of a software which uses SQLite.

The software needs to use a database file to prevent data being lost. After each of the tests, I want to delete the database file to leave everything as it was at the beginning.

The problem is that when I Try to delete the file It throws an exception which says "System.IO.IOException: The process cannot access the file '*****' because it is being used by another process". Before trying to delete the file, I'm closing and disposing of the connection like this:

if(_connection.State == System.Data.ConnectionState.Open) _connection.Close();
_connection.Dispose();

To delete the file I am using the instruction: File.Delete(_databaseFilePath); What am I doing wrong?, Do I miss something? Thanks in advance.

borja gómez
  • 1,001
  • 8
  • 19
  • 1
    I think this post is addressing the same issue: http://stackoverflow.com/questions/12532729/sqlite-keeps-the-database-locked-even-after-the-connection-is-closed – Volkan Paksoy Jul 14 '15 at 18:41
  • Thanks the post was helpful. At the end, the solution was to call GC.Collect() and sleep the Thread for some milliseconds. – borja gómez Jul 15 '15 at 07:59

0 Answers0