故障超时的SQLException [英] Troubleshooting Timeout SqlExceptions

查看:250
本文介绍了故障超时的SQLException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我无法搞清楚为什么出现一些奇怪的行为。我看到间歇性超时异常。我是pretty的确保它与卷,因为它是不可再生的我们的开发环境。作为绷带的解决方案,我试着加大了SQL命令超时六十秒,但我已经找到了,这似乎并没有帮助。下面是奇怪的一部分,当我检查发生故障的过程中我的日志,这里有开始和结束时间:

  • 在2008年9月16日16时21分49秒
  • 在2008年9月16日16点22分19秒

所以,这怎么可能,它的超时三十秒的时候,我将命令超时六十??

仅供参考,这里的异常被抛出:

  System.Data.SqlClient.SqlException:在超时过期。之前完成操作已过或服务器超时期间没有响应。
   在System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔breakConnection)
   在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   在System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand的cmdHandler,SqlDataReader的数据流,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)
   在System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
   在System.Data.SqlClient.SqlDataReader.get_MetaData()
   在System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader的DS,RunBehavior runBehavior,串resetOptionsString)
   在System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(的CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔returnStream,布尔异步)
   在System.Data.SqlClient.SqlCommand.RunExecuteReader(的CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔returnStream,字符串方法,DbAsyncResult结果)
   在System.Data.SqlClient.SqlCommand.RunExecuteReader(的CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔returnStream,字符串方法)
   在System.Data.SqlClient.SqlCommand.ExecuteReader(的CommandBehavior行为,串法)
   在System.Data.SqlClient.SqlCommand.ExecuteReader()
   在SetClear.DataAccess.SqlHelper.ExecuteReader(的CommandType命令类型,字符串的CommandText,的SqlParameter [] commandArgs)
 

解决方案

SQL命令的时间,因为你正在使用的查询需要更长的时间比执行。在查询分析器或Management Studio中,执行它的与再presentative数据在数据库中的量的,并期待在执行计划,找出哪些是缓慢的。

如果事情正在采取的的大部分时间,并描述为表扫描或聚集索引扫描,看看你是否可以创建一个索引,将打开该操作进入一键查找(索引查找或聚集索引查找)。

I have some curious behavior that I'm having trouble figuring out why is occurring. I'm seeing intermittent timeout exceptions. I'm pretty sure it's related to volume because it's not reproducible in our development environment. As a bandaid solution, I tried upping the sql command timeout to sixty seconds, but as I've found, this doesn't seem to help. Here's the strange part, when I check my logs on the process that is failing, here are the start and end times:

  • 09/16/2008 16:21:49
  • 09/16/2008 16:22:19

So how could it be that it's timing out in thirty seconds when I've set the command timeout to sixty??

Just for reference, here's the exception being thrown:

System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
   at System.Data.SqlClient.SqlDataReader.get_MetaData()
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader()
   at SetClear.DataAccess.SqlHelper.ExecuteReader(CommandType commandType, String commandText, SqlParameter[] commandArgs)

解决方案

SQL commands time out because the query you're using takes longer than that to execute. Execute it in Query Analyzer or Management Studio, with a representative amount of data in the database, and look at the execution plan to find out what's slow.

If something is taking a large percentage of the time and is described as a 'table scan' or 'clustered index scan', look at whether you can create an index that would turn that operation into a key lookup (an index seek or clustered index seek).

这篇关于故障超时的SQLException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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