.net – 什么“当前命令发生了严重错误.结果(如果有的话)应该被丢弃.“SQL Azure错误意味着什么?

我的代码遇到了一段时间

System.Data.SqlClient.SqlException
The service has encountered an error processing your request. Please try again.
Error code 40540. A severe error occurred on the current command.
The results, if any, should be discarded.
Class 20
Number 40197

这很少发生,通常会在一两分钟内消失,我无法可靠地重现它.有时,错误代码可以是40540以外的数字.

我用谷歌搜索了一下,看起来它通常是由SQL Server中的错误触发的,并且是可重现的.

我有两个选择 – 重试查询或将其视为致命并且努力破解.我更愿意更好地理解问题究竟是什么以及我是否安全重试查询.

发生此错误时是否重试查询?

最佳答案
快速谷歌搜索给了我这个.

The service has encountered an error processing your request. Please try again. Error code %d. You will receive this error, when the service is down due to software or hardware upgrades, hardware failures, or any other failover problems. Reconnecting to your SQL Database server will automatically connect you to a healthy copy of your database. You may see error codes 40143 and 40166 embedded within the message of error 40540. The error codes 40143 and 40166 provide additional information about the kind of failover that occurred. Do not modify your application to catch error codes 40143 and 40166. Your application should catch 40540 and try reconnecting to SQL Database until the resources are available and your connection is established again.

您可以访问here以获取更多信息.它说你的应用程序应该捕获40540并尝试重新连接到SQL数据库,直到资源可用并再次建立连接.

虽然从个人角度来说,我建议不要使用Sql azure,因为它很容易限制,你无法控制分配给你的资源.我所做的是在azure vm上安装sql server并在我的应用程序中使用它.

希望这对你有所帮助.

转载注明原文:.net – 什么“当前命令发生了严重错误.结果(如果有的话)应该被丢弃.“SQL Azure错误意味着什么? - 代码日志