![](/img/trans.png)
[英]Unable to connect to SQL Server session database - The wait operation timed out
[英]SQL Server Express (localdb) The wait operation timed out - query timing out at random?
我有一个简单的SELECT
查询,它返回相对较大的数据集(11k 行),并且在我的应用程序运行时随机超时。 这发生在我自己的开发笔记本电脑上,使用 localdb。 当它工作时,它几乎立即返回数据,其他时候 - Microsoft.Data.SqlClient.SqlException: The wait operation timed out.
. 当它失败时,使用 SSMS 也感觉缓慢,但它总是完成查询。
SQL如下
(@CurrentUserId int)
-- First, select Draft issues created by current user
SELECT [I].[IssueId]
,[I].[IssueGuid]
,[I].[IssueNumber]
,[I].[DateCreated]
,[I].[DateOpened]
,[I].[DateLastModified]
,[I].[DateClosed]
,[I].[Title]
,[I].[Type]
,[I].[Status]
,[I].[CreatedByUserId]
,1 AS [OrderKey]
FROM [cm].[IssuesTbl] [I]
WHERE [I].[Status] = 0 AND [I].[CreatedByUserId] = @CurrentUserId
UNION ALL
-- Last, select Open issues
SELECT [I].[IssueId]
,[I].[IssueGuid]
,[I].[IssueNumber]
,[I].[DateCreated]
,[I].[DateOpened]
,[I].[DateLastModified]
,[I].[DateClosed]
,[I].[Title]
,[I].[Type]
,[I].[Status]
,[I].[CreatedByUserId]
,2 AS [OrderKey]
FROM [cm].[IssuesTbl] [I]
WHERE [I].[Status] = 1
ORDER BY [OrderKey] ASC, [I].[DateOpened] DESC, [I].[DateCreated] DESC
执行计划在这里。
我安装了 Blitz 并运行sp_BlitzFirst
来给我一些想法,但我不确定要查找什么以及如何解决问题。 请帮忙。
@@版本:
Microsoft SQL Server 2016 (SP1) (KB3182545) - 13.0.4001.0 (X64) Oct 28 2016 18:17:30 Copyright (c) Microsoft Corporation Express Edition (64-bit) on Windows 10 Enterprise 6.3 <X64> (Build 17134: )
sp_BlitzFirst:
10 Server Performance Poison Wait Detected: RESOURCE_SEMAPHORE
For 4 seconds over the last 5 seconds, SQL Server was waiting on this particular bottleneck.
200 Wait Stats RESOURCE_SEMAPHORE
For 4 seconds over the last 5 seconds, SQL Server was waiting on this particular bottleneck.
看来你的内存有问题。 您应该检查您的状态:
SELECT
((t1.requested_memory_kb)/1024.00) MemoryRequestedMB
, CASE WHEN t1.grant_time IS NULL THEN 'Waiting' ELSE 'Granted' END AS RequestStatus
, t1.timeout_sec SecondsToTerminate
FROM sys.dm_exec_query_memory_grants t1
CROSS APPLY sys.dm_exec_sql_text(t1.sql_handle) t2
你不想等待。 同样,你应该运行
SELECT total_physical_memory_kb, available_physical_memory_kb,
total_page_file_kb, available_page_file_kb,
system_memory_state_desc
FROM sys.dm_os_sys_memory WITH (NOLOCK) OPTION (RECOMPILE);
您在这里想要的是Available physical memory is high
。 如果没有,则说明您的记忆力有问题。 那么问题是您是否有相互竞争的流程。
你可以尝试一些事情
这是我建议的代码。 我更改了以Status
开头的顺序,因为它已经按顺序排列了,但我没有将第二个字段更改为 ID - 但如果可以,请执行此操作。
SELECT [I].[IssueId]
,[I].[IssueGuid]
,[I].[IssueNumber]
,[I].[DateCreated]
,[I].[DateOpened]
,[I].[DateLastModified]
,[I].[DateClosed]
,[I].[Title]
,[I].[Type]
,[I].[Status]
,[I].[CreatedByUserId]
,CASE WHEN [I].[Status]=1 THEN 2 ELSE 1 END AS [OrderKey]
FROM [cm].[IssuesTbl] [I]
WHERE ([I].[Status] = 1)
OR ([I].[Status] = 0 AND [I].[CreatedByUserId] = @CurrentUserId)
ORDER BY [I].[Status] ASC, [I].[DateOpened] DESC, [I].[DateCreated] DESC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.