Skip to content

Commit

Permalink
Merge pull request #222 from ylorph/dispose_close_interactions
Browse files Browse the repository at this point in the history
Have Dispose(true) call Close() instead of Close() call Dispose(true).
  • Loading branch information
Giorgi authored Oct 1, 2024
2 parents 9c65872 + 3f63b43 commit 29bce0c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions DuckDB.NET.Data/DuckDBConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ public override void Close()
throw new InvalidOperationException("Connection is already closed.");
}

Dispose(true);
if (connectionReference is not null) //Should always be the case
{
connectionManager.ReturnConnectionReference(connectionReference);
}

connectionState = ConnectionState.Closed;
OnStateChange(FromOpenToClosedEventArgs);
}

public override void Open()
Expand Down Expand Up @@ -182,15 +188,10 @@ protected override void Dispose(bool disposing)
{
if (disposing)
{
// this check is to ensure exact same behavior as previous version
// where Close() was calling Dispose(true) instead of the other way around.
if (connectionState == ConnectionState.Open)
{
if (connectionReference is not null) //Should always be the case
{
connectionManager.ReturnConnectionReference(connectionReference);
}
connectionState = ConnectionState.Closed;
OnStateChange(FromOpenToClosedEventArgs);
}
Close();
}

base.Dispose(disposing);
Expand Down

0 comments on commit 29bce0c

Please sign in to comment.