Skip to content

Commit 3dfc04d

Browse files
Add additional check for closed/broken connection errors (#862)
1 parent 18a16a2 commit 3dfc04d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/SqlBindingUtilities.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,16 @@ internal static async Task OpenAsyncWithSqlErrorHandling(this SqlConnection conn
250250
/// <returns>True if the exception is a fatal SqlClientException, false otherwise</returns>
251251
internal static bool IsFatalSqlException(this Exception e)
252252
{
253+
string lowerMessage = e.Message.ToLowerInvariant();
253254
// Most SqlExceptions wrap the original error from the native driver, so make sure to check both
254-
return (e as SqlException)?.Class >= 20 || (e.InnerException as SqlException)?.Class >= 20;
255+
return (e as SqlException)?.Class >= 20
256+
|| (e.InnerException as SqlException)?.Class >= 20
257+
// TEMPORARY - Not all exceptions thrown by SqlClient are SqlExceptions, and the current SqlClient
258+
// does not correctly update the State property in all cases. So for now explicitly check for
259+
// the string containing a message indicating that the connection has been closed or broken.
260+
// This should be removed once version 5.2.0+ has been released
261+
// https://github.com/Azure/azure-functions-sql-extension/issues/860
262+
|| (lowerMessage.Contains("connection") && (lowerMessage.Contains("broken") || lowerMessage.Contains("closed")));
255263
}
256264

257265
/// <summary>

0 commit comments

Comments
 (0)