实体框架 - SQL Azure 重试策略
请任何人指导我如何使用 EF 到 SQL Azure 实施重试策略。
Could anyone guide me how to implement a retry policy with EF to SQL Azure, please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我正在使用 Transiet 故障处理框架,EF 团队提供了更好的解决方案。
上下文
上的任何原子工作。I am using the Transiet Fault Handling Framework, provided in lue of a better solution by EF team.
context
.Entity Framework 6 添加了连接弹性作为一项新功能功能可以帮助解决这个问题,引用 Microsoft 的话:“启用暂时连接故障的自动恢复”。如果您想了解更多信息,请参阅EF6 连接弹性规范。
NuGet 上的 EF6
Entity Framework 6 has added connection resiliency as a new feature to help address this, quoting from Microsoft: "enables automatic recovery from transient connection failures". Here is the Connection Resiliency Spec for EF6 if you want to learn more.
EF6 at NuGet
根据大多数文档,使用瞬态故障处理库的问题是它迫使您在应用程序中包装每个数据库调用。
如果您使用 Entity Framework 6(目前处于 alpha 版本),则有一些新的内置支持对 Azure SQL 数据库的瞬时重试(需要一些配置):这里是 link
我创建了一个库,允许您配置实体框架以重试使用故障处理块,而无需更改每个数据库调用 - 通常您只需要更改配置文件,可能还需要更改一两行代码。
这允许您将其用于 Entity Framework 或 Linq To Sql,这里是链接
The problem with using the Transient Fault Handling library according to most of the documentation out there is that it forces you to wrap every database call in your application.
If you use Entity Framework 6 (currently in alpha) then there is some new in-built support for transient retries with Azure SQL Database (with a little bit of configuration): here is the link
I've created a library which allows you to configure Entity Framework to retry using the Fault Handling block without needing to change every database call - generally you will only need to change your config file and possibly one or two lines of code.
This allows you to use it for Entity Framework or Linq To Sql, here is the link
此 Azure 论坛主题包含一些涵盖该主题的优质资源的链接。似乎还没有任何“官方”消息。但有一些开源项目可以为您提供一个良好的开端。
http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/3a9ed384-5374-438e-a8a4-ff4bd8000738/#27b5251a-bff5-4282-980c-ad43fdd85591
从答案:
http://blogs.msdn.com/b/appfabriccat/archive/2010/10/28/best-practices-for-handling-transient-conditions-in-sql-azure -client-applications.aspx
我个人没有使用博客提到的库。相反,我能够使用带有 TRY/CATCH 的简单 WHILE 循环来监视可以安全重试的特定 SQL EXCEPTION 错误号。还有一个计数器基本上可以防止它永远“重试”。
This Azure Forum thread has some links to good resources that cover this topic. There doesn't seem to be anything 'official' quite yet. But there are some open source projects that give you a pretty good start.
http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/3a9ed384-5374-438e-a8a4-ff4bd8000738/#27b5251a-bff5-4282-980c-ad43fdd85591
From the answer:
http://blogs.msdn.com/b/appfabriccat/archive/2010/10/28/best-practices-for-handling-transient-conditions-in-sql-azure-client-applications.aspx
I personally didn't use the library the blog mentions. Instead I was able to get away with a simple WHILE LOOP with a TRY/CATCH that watched for the specific SQL EXCEPTION Error Numbers which were safe to retry. There is also a counter which basically prevents it from 'retrying' forever.
Windows Server AppFabric 客户咨询团队在 这篇博文。
基本上,他们有多种不同的方法来使用瞬态故障处理框架(该框架已被 瞬态故障处理应用程序块,这是类似的)以便提供重试。
The Windows Server AppFabric Customer Advisory Team have provided some fairly detailed guidance around retries in this blog post.
Basically, they've got a number of different ways of using the Transient Fault Handling Framework (which has been since superseded by the Transient Fault Handling Application Block, which is similar) in order to provide retries.