Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Javad Rahnama authored and Javad Rahnama committed Mar 23, 2023
1 parent a2f6432 commit 594dbeb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Expand Up @@ -1417,6 +1417,7 @@ private async Task ReconnectAsync(int timeout)
if (e.Class >= TdsEnums.FATAL_ERROR_CLASS)
{
SqlClientEventSource.Log.TryTraceEvent("<sc.SqlConnection.ReconnectAsync|INFO> 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);
Expand Down
Expand Up @@ -23,23 +23,30 @@ 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
{
int result2 = cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
Assert.True(ex.Class >= 20);
Assert.Equal(11, ex.Class);
Assert.NotNull(ex.InnerException);
SqlException innerEx = Assert.IsType<SqlException>(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);
}
}

Expand Down

0 comments on commit 594dbeb

Please sign in to comment.