什么是“当前命令发生严重错误,应该丢弃结果(如果有)。” SQL Azure错误是什么意思?

问题描述:

在一段时间后我的代码遇到什么是“当前命令发生严重错误,应该丢弃结果(如果有)。” 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 

出现这种情况非常罕见,通常会消失在一两分钟,我不能可靠地重现它。有时Error code可能是40540以外的数字。

我已经Google了一下,看起来像它通常由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虚拟机上安装sql server并在我的应用程序中使用它。

希望这可以帮助你。

+0

我已经使用SQL Azure很多没有问题。但是,如果您像使用SQL Server一样使用它,则会遇到问题。 – Craig 2013-02-11 22:14:01

+0

您能否详细说明一下。我不明白你的意思,就好像它与SQL Server一样? – gaurav 2013-02-11 22:30:20

+0

SQL Azure旨在扩展,而不是扩展。 SQL Azure数据库不在高端服务器上运行,但虚拟机与其他用户共享。因此,对于SQL Server,您只需在其上启动数千个查询,并且通常不会出现问题,而使用SQL Azure则不应这样做。您需要将负载分配到多个数据库以使其按比例扩展。在命令上使用重试。如果可能的话,请使用缓存,以便不必访问数据库或使用Table/Blob存储。所有像Stack Overflow这样的大型SQL站点的优化现在都适用于所有人。 – Craig 2013-02-11 22:37:29

我遇到类似的错误:我跟着http://social.msdn.microsoft.com/Forums/en-US/bbe589f8-e0eb-402e-b374-dbc74a089afc/severe-error-in-current-command-during-datareaderread的答案,解决问题..

避免读者的looping;加载数据在一个DataTable

DataTable table = new DataTable(); 
table.Load(reader); 
reader.Close();