SQL Azure数据库重试逻辑
发布时间:2020-12-12 16:22:56 所属栏目:MsSql教程 来源:网络整理
导读:我已经实现了以下代码,用于在写入Azure数据库时使用指数退避处理INSERT / UPDATE重试逻辑. static SqlConnection TryOpen(this SqlConnection connection){ int attempts = 0; while (attempts 5) { try { if (attempts 0) System.Threading.Thread.Sleep(((i
我已经实现了以下代码,用于在写入Azure数据库时使用指数退避处理INSERT / UPDATE重试逻辑.
static SqlConnection TryOpen(this SqlConnection connection) { int attempts = 0; while (attempts < 5) { try { if (attempts > 0) System.Threading.Thread.Sleep(((int)Math.Pow(3,attempts)) * 1000); connection.Open(); return connection; } catch { } attempts++; } throw new Exception("Unable to obtain a connection to SQL Server or SQL Azure."); } 但是我应该考虑为我的数据库读取应用重试逻辑吗?或者SqlCommand.CommandTimeout()方法是否足够?我的大多数读取都是使用以下代码创建的: Dim myDateAdapter As New SqlDataAdapter(mySqlCommand) Dim ds As New DataSet myDateAdapter.Fill(ds,"dtName") 很难知道在Azure的生产环境中会发生什么样的瞬态错误,所以我现在尝试尽可能多地进行缓解. 解决方法我认为重试将成为您的Windows Azure SQL数据库操作的一部分.您是否看过Microsoft模式和实践发布的transient fault handling application block,而不是实现自定义解决方案,特别是SQL数据库? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- sql-server – 加速没有子句的巨大DELETE FROM的方法
- selectmethod=cursor的含义及其使用
- sql – 如何在Hibernate中使用数组字段制作条件
- 如何从提供数据库数据生成Symfony灯具YML?
- 允许SQL相同的列名
- sqlserver 2005 模糊查询怎么处理null
- sql-server – delphi dbgrid布尔值,接受f fa fal fals fal
- sql – django中的完全外连接
- 执行存储过程报错:“SQLSERVER 内部错误。文本管理器无法继
- Element type "Resource" must be followed by