Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/Data.Common/ADO.NET/FileConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ public override void ChangeDatabase(string databaseName)
/// </summary>
public override void Close()
{
(DataSourceProvider as IDisposable)?.Dispose();
state = ConnectionState.Closed;
}

Expand Down Expand Up @@ -233,6 +232,9 @@ public override void Close()
/// </summary>
public override void Open()
{
if (State == ConnectionState.Open)
throw new InvalidOperationException("Connection is already open.");

if (DataSourceProvider is null)
{
if (!CreateIfNotExist)
Expand Down Expand Up @@ -322,11 +324,15 @@ public override ValueTask DisposeAsync()
/// <summary>
/// Disposes the connection.
/// </summary>
protected new void Dispose()
protected override void Dispose(bool disposing)
{
(DataSourceProvider as IDisposable)?.Dispose();
base.Dispose();
state = ConnectionState.Closed;
if (disposing)
{
(DataSourceProvider as IDisposable)?.Dispose();
DataSourceProvider = null;
state = ConnectionState.Closed;
}
base.Dispose(disposing);
}

private DataTable GetTablesSchema()
Expand Down
11 changes: 7 additions & 4 deletions src/Data.Common/ADO.NET/FileDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ public override int RecordsAffected
/// </summary>
public override bool HasRows => result.HasRows;

public override void Close() => Dispose();
public override void Close()
{
log.LogDebug($"{GetType()}.{nameof(Close)}() called.");
fileReader.Dispose();
}

/// <summary>
/// Advances to the next result, when reading the results of batch SQL statements.
Expand Down Expand Up @@ -714,10 +718,9 @@ public override ValueTask DisposeAsync()
/// <summary>
/// Disposes of the resources used by this instance.
/// </summary>
protected new void Dispose()
protected override void Dispose(bool disposing)
{
log.LogDebug($"{GetType()}.{nameof(Dispose)}() called.");
fileReader.Dispose();
base.Dispose(disposing);
}

/// <summary>
Expand Down
15 changes: 9 additions & 6 deletions src/Data.Common/ADO.NET/FileTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,18 @@ public override ValueTask DisposeAsync()
#endif

/// <inheritdoc/>
protected new void Dispose()
protected override void Dispose(bool disposing)
{
log.LogDebug($"{GetType()}.{nameof(Dispose)}() called.");
if (disposing)
{
log.LogDebug($"{GetType()}.{nameof(Dispose)}() called.");

if (!TransactionDone)
Rollback();
if (!TransactionDone)
Rollback();

base.Dispose();
Writers.Clear();
Writers.Clear();
}
base.Dispose(disposing);
}

/// <inheritdoc/>
Expand Down
2 changes: 2 additions & 0 deletions tests/Data.Tests.Common/InsertTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static void Insert_ShouldInsertData<TFileParameter>(Func<FileConnection<T

// Assert
Assert.Equal(1, rowsAffected);
connection.Close();
connection.Open();

// Act - Verify the inserted record exists in the locations table
Expand Down Expand Up @@ -61,6 +62,7 @@ public static void Insert_ShouldInsertNullData<TFileParameter>(Func<FileConnecti

// Assert
Assert.Equal(1, rowsAffected);
connection.Close();
connection.Open();

// Act - Verify the inserted record exists in the locations table
Expand Down
Loading