过程从 ADO.NET 超时,但在 SSMS 中不超时
我有一个存储过程,由于从代码运行它时超时(超时设置为 30),它给了我一个 SqlException。
当我直接在 Management Studio 中运行该过程时,它的执行时间不到 1 秒。
我也只在针对特定数据库运行它时才会超时。
当我使用其他数据库时,它很快完成,没有错误。
这是完整的错误消息:
System.Data.SqlClient.SqlException (0x80131904): 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.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
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.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
此堆栈跟踪对任何人都意味着什么吗?看起来我的存储过程可能已完成,但在尝试读取某种元数据时超时?
我尝试在进程运行时查看该进程,但它已暂停。 sys.dm_os_waiting_tasks 将等待类型显示为 IO_COMPLETION(如果有任何用处)。我在数据库上看到的使用 sp_who2 'active' 的唯一进程是超时进程和我的活动 SSMS 窗口,因此我认为这不是一个阻塞问题。我验证了该数据库与工作数据库具有相同的索引,并运行 dbcc checkdb 没有任何错误。如何确定超时的原因?
I've got a stored procedure that is giving me a SqlException because of a timeout when I run it from code (with timeout set to 30).
When I run the procedure directly in Management Studio, it executes in under 1 second.
I also only get the timeout when running it against a specific database.
When I use other databases it finishes quickly without an error.
Here is the full error message:
System.Data.SqlClient.SqlException (0x80131904): 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.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
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.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
Does this stack trace mean anything to anyone? It looks like maybe my sproc completed and it timed out while trying to read some kind of meta data?
I tried looking at the process while it is running and it is Suspended. sys.dm_os_waiting_tasks shows the wait type as IO_COMPLETION, if that's of any use. The only processes I see on the database using sp_who2 'active' are the one timing out and my active SSMS window so I don't think it's a blocking issue. I verified this database has the same indeces as a working database and ran dbcc checkdb without any errors on it. How can I determine the cause of the timeout?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将超时会话的 SET 选项与未超时会话的 SET 选项进行比较:
当您发现某些不同时,请尝试将 SSMS 查询中的每个设置更改为相反的设置,直到超时(或手动设置)在发送查询之前在应用程序代码中设置选项)。现在,我手头没有 2005 年的实例,所以还没有测试这个查询。您可能需要注释掉一个或多个列名称。
You can compare the SET options for the session that is timing out to those from the session that is not:
When you find some that are different, experiment with changing each setting to the opposite in your SSMS query until you get the timeout (or manually setting the option(s) in your app code before sending the query). Now, I don't have a 2005 instance handy, so have not tested this query. You may need to comment out one or more column names.
删除并重新创建 SP 将清除损坏的缓存执行计划
Dropping and re-creating the SP will clear the corrupted, cached Execution Plan