diff --git a/Snowflake.Data/Client/SnowflakeDbConnection.cs b/Snowflake.Data/Client/SnowflakeDbConnection.cs index 8690aa807..24c753ca0 100755 --- a/Snowflake.Data/Client/SnowflakeDbConnection.cs +++ b/Snowflake.Data/Client/SnowflakeDbConnection.cs @@ -257,9 +257,18 @@ public override void Open() } catch (Exception e) { + // Otherwise when Dispose() is called, the close request would timeout. _connectionState = ConnectionState.Closed; - logger.Error(e.Message); - throw; + logger.Error("Unable to connect: ", e); + if (e is SnowflakeDbException) + { + throw; + } + throw new SnowflakeDbException( + e, + SnowflakeDbException.CONNECTION_FAILURE_SSTATE, + SFError.INTERNAL_ERROR, + "Unable to connect. " + e.Message); } } diff --git a/Snowflake.Data/Core/Session/SessionPool.cs b/Snowflake.Data/Core/Session/SessionPool.cs index e4c7cd689..0be796727 100644 --- a/Snowflake.Data/Core/Session/SessionPool.cs +++ b/Snowflake.Data/Core/Session/SessionPool.cs @@ -164,9 +164,6 @@ internal Task NewSessionAsync(String connectionString, SecureString p .OpenAsync(cancellationToken) .ContinueWith(previousTask => { - if (previousTask.IsCanceled) - cancellationToken.ThrowIfCancellationRequested(); - if (previousTask.IsFaulted && previousTask.Exception != null) throw previousTask.Exception; @@ -174,10 +171,10 @@ internal Task NewSessionAsync(String connectionString, SecureString p throw new SnowflakeDbException( SnowflakeDbException.CONNECTION_FAILURE_SSTATE, SFError.INTERNAL_ERROR, - "Async open on connection failure"); + "Failure while opening session async"); return session; - }, cancellationToken); + }, TaskContinuationOptions.NotOnCanceled); } catch (Exception e) {