System.Data.SQLite
Ticket Change Details
Not logged in
Overview

Artifact ID: 3021e258a7fa610934535efcfc4e7e3eec001b12
Ticket: 165af4c68cd9dc26e6145abd44904f520cf18ded
System.Data.SQLite.EF6 has lock on file after DbContext.Dispose()
User & Date: anonymous 2020-03-17 20:36:42
Changes

  1. foundin changed to: "1.0.112"
  2. icomment:
    Trying to delete the file after performing my unit test failed. It failed because the file is still open used.
    
    System.IO.IOException : The process cannot access the file 'D:\ALAIN\GitHub\RPLV\DataAccessLayerTests\bin\Debug\test.sqlite' because it is being used by another process.
    
    Following is the code I used to reproduce the problem.
            [Fact]
            public void Open_close_with_Context()
            {
    
                //--- Setup
                SQLiteConnection connection = RplvContextFactory.Instance.CreateConnection($"Data Source={_testFile}") as SQLiteConnection;
                RplvContext contextTest = new RplvContext(connection, true);
                contextTest.Database.Connection.Should().BeSameAs(connection);
    
                //--- Action
                var result = contextTest.LuminaireDb.ToList();
    
                //--- Verification
                contextTest.Database.Connection.State.Should().Be(ConnectionState.Closed);
    
                //--- Action
                contextTest.Dispose();
                contextTest = null;
    
                //--- Verification
    
                File.Exists(_testFile).Should().BeTrue();
    
                // failed throw IOException
                File.Delete(_testFile);
            }
    
  3. login: "anonymous"
  4. mimetype: "text/plain"
  5. private_contact changed to: "22e3ca59f6ea2f967118a9b57df213a0a0bce9a2"
  6. severity changed to: "Critical"
  7. status changed to: "Open"
  8. title changed to:
    System.Data.SQLite.EF6 has lock on file after DbContext.Dispose()
    
  9. type changed to: "Code_Defect"