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); }