我如何解决我的Azure角色连接到SQL Azure的突然丧失? [英] How do I address sudden loss of connection to SQL Azure in my Azure role?

查看:263
本文介绍了我如何解决我的Azure角色连接到SQL Azure的突然丧失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Azure角色抓住的东西从数据库中处理 - 它持有系统的一个实例.Data.SqlClient.SqlConnection 并定期创建一个的SqlCommand 实例,并执行一个SQL查询。

My Azure role grabs stuff to process from a database - it holds an instance of System.Data.SqlClient.SqlConnection and periodically creates an SqlCommand instance and executes an SQL query.

现在偶尔(通常在数天一次)运行查询将触发的SQLException 例外

Now once in a while (usually once in several days) running a query will trigger an SqlException exception

该服务遇到了一个错误处理您的请求。请再试一次。错误code 40143。
  当前命令发生了严重错误。结果,如果有的话,应被丢弃。

The service has encountered an error processing your request. Please try again. Error code 40143. A severe error occurred on the current command. The results, if any, should be discarded.

这一点我已经见过很多次,现在我的code捕获它,调用的Dispose()的SqlConnection 实例,然后重新打开连接,并试查询。后者通常会导致另一个的SQLException 例外

Which I've already seen many times and now my code catches it, calls Dispose() on the SqlConnection instance and then reopens the connection and retries the query. The latter typically results in another SqlException exception

超时过期。操作完成或服务器之前经过的超时时间没有响应。

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

它看起来pretty很像SQL Azure的服务器没有响应,或者出于某种原因不可用。

Which looks pretty much like SQL Azure server not responding or being unavailable for whatever reason.

目前我的code没有赶上后者的例外,它在外面传播RoleEntryPoint.Run()和角色重新启动。重新启动通常需要约十分钟,一旦完成问题走了一天左右。

Currently my code doesn't catch the latter exception, it is propagated outside RoleEntryPoint.Run() and the role is restarted. Restart typically takes about ten minutes and once it completes the problem is gone for a day or so.

我不喜欢我的角色重新启动 - 这是需要一段时间,我的服务功能受阻。我想做点什么聪明。

I don't like my role restarting - it's takes a while and my service functionality is hindered. I'd like to do something smarter.

什么是解决这一问题的策略?我是否应该重新进行查询几次,多少次又什么区间?我应该做点别的?当我放弃,让角色只需重新启动?

What would be a strategy to address this problem? Should I retry the query several times and how many times and with what interval? Should I do something else? When do I give up and let the role just restart?

推荐答案

我强烈建议你看一下的瞬态故障处理框架SQL Azure的

I would strongly recommend you have a look at the Transient Fault Handling Framework for SQL Azure

这将帮助你处理重试为连接和查询尝试的逻辑,我在生产中使用这个和它的伟大工程。还有一个很好的文章<一个href=\"http://social.technet.microsoft.com/wiki/contents/articles/sql-azure-connection-management.aspx\"相对=nofollow> TechNet上这可能是一些使用。

This will help you handle retry logic for both connection and query attempts, I am using this in production and it works great. There is also a nice article on technet that might be of some use.

它看起来像这样一直在的瞬态故障处理应用程序块

It looks like this has been picked up by the patterns and practices team at The Transient Fault Handling Application Block

这篇关于我如何解决我的Azure角色连接到SQL Azure的突然丧失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆