English 中文(简体)
LIN LIN
原标题:Debugging a tough LINQ-to-SQL Timeout

I m 在试图执行LINQ(-to-SQL)问询时,会遇到时间差错

系统.Data.SqlClient.SqlException: 停工。 运行完成之前或服务器尚未答复的未清期间。

现在,而不是。 只是一个缓慢的问题:

  • I run the equivalent SQL in SQL Management Studio and it completes quickly (2 seconds)
  • I m setting my CommandTimeout to 2 minutes.
  • When I execute the very same query in a unit test, it completes successfully and quickly. That is: I m only getting this timeout when I m running this query alongside other queries. The timeout always occurs at the same call.

最后一个项目使我想,我会陷入某种数据库方面的僵局:有些地方的僵局使问题受阻,而时间的缩短则导致中断的联系。

对这一想法的困扰是,Im only在数据目录中选择会造成问题。 (我的确在不同的数据库/数据库中插入。) 我也没有明确的交易。 这使我想起一点:问询行为正好像是一个僵局,但我从未陷入过一种僵局,这种僵局是由以前某种交易孤立问题造成的,而这里的情况(首先看一看问题)。

我期待着就如何缓解这一问题提出建议。 我应该研究什么事情来决定这一问题的原因?

EDIT

一些可能有用的说明:

  • I m querying against a view that references:
    • Other views in the same database
    • Synonyms that point to tables in another database via a Linked Server.
  • This view is using union to join the results of several queries together

EPILOGUE

最后,我通过重新处理我的询问,解决了核心问题。 原来的表格不止一次(通过不同的观点)。 重新编造的版本绕过了所有这些内容,时间已经消失。

最佳回答

在申请等待期间(超过2分钟?) 在一个问讯窗口中操作:

;with Blockers AS
(SELECT
     r.session_id AS spid
         ,r.cpu_time,r.reads,r.writes,r.logical_reads 
         ,r.blocking_session_id AS BlockingSPID
         ,LEFT(OBJECT_NAME(st.objectid, st.dbid),50) AS ShortObjectName
         ,LEFT(DB_NAME(r.database_id),50) AS DatabaseName
         ,s.program_name
         ,s.login_name
         ,OBJECT_NAME(st.objectid, st.dbid) AS ObjectName
         ,SUBSTRING(st.text, (r.statement_start_offset/2)+1,( (CASE r.statement_end_offset
                                                                   WHEN -1 THEN DATALENGTH(st.text)
                                                                   ELSE r.statement_end_offset
                                                               END - r.statement_start_offset
                                                              )/2
                                                            ) + 1
                   ) AS SQLText
     FROM sys.dm_exec_requests                          r
         JOIN sys.dm_exec_sessions                      s ON r.session_id = s.session_id
         CROSS APPLY sys.dm_exec_sql_text (sql_handle) st
     --WHERE r.session_id > 50
)
SELECT Blockers.* FROM Blockers

它将在行程时向各位展示所有区块。

问题回答

你们是否相信连接池是靠未收资源吃的?

逐个地总结一下你的SqlDataContext,看问题是否继续存在。





相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签