From 594dbebbd37debf0a9b9eddae5234917d3111f98 Mon Sep 17 00:00:00 2001 From: Javad Rahnama Date: Thu, 23 Mar 2023 11:11:37 -0700 Subject: [PATCH] commit --- .../src/Microsoft/Data/SqlClient/SqlConnection.cs | 1 + .../SQL/ExceptionTest/ConnectionExceptionTest.cs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs index cd8ec4828c..0c2330267d 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs @@ -1417,6 +1417,7 @@ private async Task ReconnectAsync(int timeout) if (e.Class >= TdsEnums.FATAL_ERROR_CLASS) { SqlClientEventSource.Log.TryTraceEvent(" Original ClientConnectionID {0} - Fatal Error occured. Error Class: {1}", _originalConnectionId, e.Class); + // Errors 20-25, usuallyterminate the database connection InnerConnection.CloseConnection(InnerConnection.Owner, ConnectionFactory); } throw SQL.CR_AllAttemptsFailed(e, _originalConnectionId); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ConnectionExceptionTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ConnectionExceptionTest.cs index d5c079ea00..42df47a35c 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ConnectionExceptionTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ConnectionExceptionTest.cs @@ -23,12 +23,15 @@ public void TestConnectionStateWithErrorClass20() { using TestTdsServer server = TestTdsServer.StartTestServer(); using SqlConnection conn = new(server.ConnectionString); + conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT 1"; int result = cmd.ExecuteNonQuery(); + Assert.Equal(-1, result); - Assert.Equal("Open", conn.State.ToString()); + Assert.Equal(System.Data.ConnectionState.Open, conn.State); + server.Dispose(); try { @@ -36,10 +39,14 @@ public void TestConnectionStateWithErrorClass20() } catch (SqlException ex) { - Assert.True(ex.Class >= 20); + Assert.Equal(11, ex.Class); + Assert.NotNull(ex.InnerException); + SqlException innerEx = Assert.IsType(ex.InnerException); + Assert.Equal(20, innerEx.Class); + Assert.StartsWith("A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.", innerEx.Message); // Since the server is not accessible driver can close the close the connection // It is user responsibilty to maintain the connection. - Assert.Equal("Closed", conn.State.ToString()); + Assert.Equal(System.Data.ConnectionState.Closed, conn.State); } }