From e434e18db044a99717af74f276faf52b4308f241 Mon Sep 17 00:00:00 2001 From: Piotr Bulawa Date: Wed, 8 Nov 2023 09:52:54 +0100 Subject: [PATCH] Change behavior of Dispose --- .../Client/SnowflakeDbConnection.cs | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/Snowflake.Data/Client/SnowflakeDbConnection.cs b/Snowflake.Data/Client/SnowflakeDbConnection.cs index 36c35011f..b773a0150 100755 --- a/Snowflake.Data/Client/SnowflakeDbConnection.cs +++ b/Snowflake.Data/Client/SnowflakeDbConnection.cs @@ -26,7 +26,7 @@ public class SnowflakeDbConnection : DbConnection internal int _connectionTimeout; - private bool disposed = false; + private bool _disposed = false; private static Mutex _arraybindingMutex = new Mutex(); @@ -361,21 +361,30 @@ protected override DbCommand CreateDbCommand() protected override void Dispose(bool disposing) { - if (disposed) - return; - - try - { - this.Close(); - } - catch (Exception ex) + if (!_disposed) { - // Prevent an exception from being thrown when disposing of this object - logger.Error("Unable to close connection", ex); + if (disposing) + { + try + { + Close(); + } + catch (Exception ex) + { + // Prevent an exception from being thrown when disposing of this object + logger.Error("Unable to close connection", ex); + } + } + else + { + SfSession?.close(); + SfSession = null; + _connectionState = ConnectionState.Closed; + } + + _disposed = true; } - disposed = true; - base.Dispose(disposing); }