question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can the SqlServerTransientExceptionDetector be moved to System.Data.SqlClient?

See original GitHub issue

From @avantida on October 18, 2018 8:17

The SqlServerTransientExceptionDetector class is really handy to detect if a Sql operation needs to be retried while building anything based on a SqlConnection. It basically is the core component driving the SqlServerRetryingExecutionStrategy of .NET EF Core. (which used to be the AzureSqlExecutionStrategy in EF)

This logic is sort of replicated also in the Enterprise Library Transient Fault Handling Application Block and then again even in the Elastic database tools for Azure SQL Database

Moving this code ‘upstream’ would aid a lot to enable reliable operation with Azure Sql with any of the SQL compatible .NET Core Data Access tools out there.

Today we’re not falling in the pit of success to run our code on Azure. (We’re using Dapper @NickCraver )

Copied from original issue: aspnet/EntityFrameworkCore#13665

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
Plasmacommented, Dec 17, 2019

Really supportive of having this in the base package (or an extension package) with a production-ready integration working. The guidance on Azure website and MSDN is a total mess.

  • There was originally reference to TOPAZ library and ReliableSqlConnection, that is now obsolete.

  • The Azure docs provide a range of error codes to be retried, https://docs.microsoft.com/en-us/azure/sql-database/troubleshoot-connectivity-issues-microsoft-azure-sql-database#transient-fault-error-messages with no clear production-ready strategy to handle them (just wrap connection.Open? What about command execution? What about pooled connections?).

  • As mentioned in this ticket, there are multiple implementations of the same logic, but are tied to the higher-level frameworks (Elastic pools, EF) instead of being based on the low-level client

  • When SqlConnection was updated to support retries, it was flagged as the replacement of ReliableSqlConnection, but it doesn’t actually work well, so back to square one.

  • SqlConnection and other classes are sealed, making it difficult to override methods to support some kind of retry, so the reliable connection can be provided to 3rd party code that expects SqlConnection etc

Any suggestions about where and how the retry logic should be placed for production-ready code would be appreciated, but going forward, this being built-in to the package itself would be ideal.

2reactions
avantidacommented, May 29, 2020

@roji Thanks for the heads up, read the (rather long) discussion there. And I agree that to be the way forward, and unfortunately with Azure SQL it still is required. It would indeed be a lot better if Azure SQL could handle the resilience better server-side, but I’m assuming this has historical and deep architectural reasons, not easily remediated.

I was also not aware of the ConnectRetry* properties for the connectionstring, and we will also give that a try.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is wrong with this code. Why can't I use SqlConnection?
Go to solution explorer > right click & click manage NuGet packages > and install System.data.SqlClient 4.5.1. or later. Click here to ...
Read more >
Replacing System.Data.SqlClient with Microsoft. ...
Now, there is a request to replace the System.Data.SqlClient with Microsoft.Data.SqlClient due to end of support for that library.
Read more >
Retry Transient Failures Using SqlClient / ADO.NET With ...
It does note SqlServerTransientExceptionDetector is an internal API, but it works for now. There's an issue to track moving it somewhere else: ...
Read more >
Using Microsoft.Data.SqlClient with Entity Framework 6
Want to use Microsoft.Data.SqlClient with Entity Framework 6 - this is now possible! This blog post describes the why and how.
Read more >
The new Microsoft.Data.SqlClient explained
SqlClient" is a swap out for the existing "System.Data.SqlClient" namespace. The namespace change is needed because the new Data Provider resides in a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found