Skip to content

Commit 050808b

Browse files
Capture only network related errors.
1 parent a7f3587 commit 050808b

File tree

1 file changed

+17
-2
lines changed
  • tracer/test/test-applications/integrations/Samples.Microsoft.Data.SqlClient

1 file changed

+17
-2
lines changed

tracer/test/test-applications/integrations/Samples.Microsoft.Data.SqlClient/Program.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private static DbConnection OpenConnection(Type connectionType)
5353
connection.Open();
5454
return connection;
5555
}
56-
catch (SqlException ex)
56+
catch (SqlException ex) when (IsRetryableConnectionError(ex))
5757
{
5858
lastException = ex;
5959
connection?.Dispose();
@@ -68,7 +68,7 @@ private static DbConnection OpenConnection(Type connectionType)
6868
}
6969
catch (Exception ex)
7070
{
71-
// Non-SqlException errors (reflection issues, etc.) should fail the test
71+
// Other errors (reflection issues, etc.) should fail the test
7272
Console.WriteLine($"Unexpected error opening connection: {ex}");
7373
throw;
7474
}
@@ -81,5 +81,20 @@ private static DbConnection OpenConnection(Type connectionType)
8181
Environment.Exit(13);
8282
return null;
8383
}
84+
85+
static bool IsRetryableConnectionError(SqlException ex)
86+
{
87+
return ex.Number == -1 || // Generic network error
88+
ex.Number == -2 || // Connection timeout
89+
ex.Number == 2 || // Network path not found
90+
ex.Number == 53 || // SQL Server not found
91+
ex.Number == 64 || // Connection broken
92+
ex.Number == 258 || // Wait timeout
93+
ex.Number == 10053 || // Connection aborted
94+
ex.Number == 10054 || // Connection reset
95+
ex.Number == 10060 || // Connection timeout
96+
ex.Number == 10061 || // Connection refused
97+
ex.Number == 11001; // DNS failure
98+
}
8499
}
85100
}

0 commit comments

Comments
 (0)