2014-02-06 30 views
0

我有一個查詢,鏈接很多表。所以當執行一個存儲過程,它給...超時時間已過..在我的查詢

Timeout expired. 
The timeout period elapsed prior to completion of the operation or the server is not responding. 

我能做些什麼..我可以增加SQL服務器的時間。我正在使用SQl 2008.你能幫我解決這個問題嗎?

+1

給我您的查詢... – pankeel

回答

2

當一個事務持有在數據資源的鎖定和另一個事務請求不兼容的鎖定在相同的資源,則請求被阻斷,請求者進入等待狀態。默認情況下,被阻止的請求會一直等待,直到阻塞者釋放干擾鎖定。 要獲得鎖的信息,包括當前授予該會話正在等待會議和鎖兩把鎖,查詢動態管理視圖(DMV)sys.dm_tran_locks爲:

SELECT -- use * to explore other available attributes 
request_session_id AS spid, 
resource_type AS restype, 
resource_database_id AS dbid, 
DB_NAME(resource_database_id) AS dbname, 
resource_description AS res, 
resource_associated_entity_id AS resid, 
request_mode AS mode, 
request_status AS status 
FROM sys.dm_tran_locks; 

在查詢的輸出,你將獲得正在等待共享/排他鎖的spid。通過觀察具有相同resresid值的行,您可以獲得涉及的spid's。 進一步獲取更多信息,您可以執行以下代碼以獲取有關阻止鏈中涉及的進程的連接,會話和阻止信息。

-- Connection info: 
SELECT -- use * to explore 
session_id AS spid, 
connect_time, 
last_read, 
last_write, 
most_recent_sql_handle 
FROM sys.dm_exec_connections 
WHERE session_id IN(--spid found in above query); 
-- Session info 
SELECT -- use * to explore 
session_id AS spid, 
login_time, 
host_name, 
program_name, 
login_name, 
nt_user_name, 
last_request_start_time, 
last_request_end_time 
FROM sys.dm_exec_sessions 
WHERE session_id IN(--spid found in above query); 

-- Blocking 
SELECT -- use * to explore 
session_id AS spid, 
blocking_session_id, 
command, 
sql_handle, 
database_id, 
wait_type, 
wait_time, 
wait_resource 
FROM sys.dm_exec_requests 
WHERE blocking_session_id > 0; 

--SQL text of the connections involved in the blocking chain: 
SELECT session_id, text 
FROM sys.dm_exec_connections 
CROSS APPLY sys.dm_exec_sql_text(most_recent_sql_handle) AS ST 
WHERE session_id IN(--spid found in above query); 

一旦涉足SPID的,你可以使用KILL命令KILL <spid>或存儲過程中使用命令設置LOCK_TIMEOUT的SPID:SET LOCK_TIMEOUT <milliseconds>;

1

超時是從來沒有在sql服務器,但總是在客戶端調用它們。因此,如果您無法調整查詢(可能是這種情況),請更改用於發出查詢的應用程序中的超時時間。

1

使用SQL Server Management Studio中

要配置遠程查詢超時選項

  1. 在對象資源管理器中,右鍵單擊服務器並選擇屬性。
  2. 單擊連接節點。
  3. 在遠程服務器連接下,在遠程查詢超時框中, 鍵入或選擇0到2,147,483,647之間的值,以設置SQL Server在超時之前等待的最大秒數 。

See full details here

相關問題