SQL Azure数据库重试逻辑

前端之家收集整理的这篇文章主要介绍了SQL Azure数据库重试逻辑前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经实现了以下代码,用于在写入Azure数据库时使用指数退避处理INSERT / UPDATE重试逻辑.
  1. static sqlConnection TryOpen(this sqlConnection connection)
  2. {
  3. int attempts = 0;
  4. while (attempts < 5)
  5. {
  6. try
  7. {
  8. if (attempts > 0)
  9. System.Threading.Thread.Sleep(((int)Math.Pow(3,attempts)) * 1000);
  10. connection.Open();
  11. return connection;
  12. }
  13. catch { }
  14. attempts++;
  15. }
  16. throw new Exception("Unable to obtain a connection to sql Server or sql Azure.");
  17. }

但是我应该考虑为我的数据库读取应用重试逻辑吗?或者sqlCommand.CommandTimeout()方法是否足够?我的大多数读取都是使用以下代码创建的:

  1. Dim myDateAdapter As New sqlDataAdapter(MysqLCommand)
  2. Dim ds As New DataSet
  3. myDateAdapter.Fill(ds,"dtName")

很难知道在Azure的生产环境中会发生什么样的瞬态错误,所以我现在尝试尽可能多地进行缓解.

解决方法

我认为重试将成为您的Windows Azure sql数据库操作的一部分.

您是否看过Microsoft模式和实践发布的transient fault handling application block,而不是实现自定义解决方案,特别是sql数据库

猜你在找的MsSQL相关文章