当我们在ASP.NET页面上执行一个存储过程时,它会在SQL Server上超时并抛出异常Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
。但是当我在SSMS中执行同样的存储过程时,它返回得相对较快。SQL Server和IIS在同一台机器上。我在两个地方都使用相同的用户登录。其他页面都没有问题。
当我们在ASP.NET页面上执行一个存储过程时,它会在SQL Server上超时并抛出异常Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
。但是当我在SSMS中执行同样的存储过程时,它返回得相对较快。SQL Server和IIS在同一台机器上。我在两个地方都使用相同的用户登录。其他页面都没有问题。
Use YourDatabase;
SELECT *
FROM sys.dm_exec_cached_plans
CROSS APPLY sys.dm_exec_sql_text(plan_handle)
CROSS APPLY sys.dm_exec_query_plan(plan_handle)
cross APPLY sys.dm_exec_plan_attributes(plan_handle) AS epa
where sys.dm_exec_sql_text.OBJECTID=object_id('YourProcName')
and attribute='set_options'
1) ADO.Net 命令到 SQL Server 的默认超时时间为 30 秒。您可以在 SqlCommand 对象上将其更改为更高的值(或 0 禁用超时)。当运行查询时,SSMS 没有超时。
2) 但可能是查询超时,因为其他事情阻止它运行。在等待 asp.net 页面的响应时,您能否在 SQL Server 上运行 sp_who2 并检查 Blk 列 - 如果在同一行中具有与 SPID 不同的值的条目,则发生了某些阻塞。
尝试增加CommandTimeout
属性,看看是否解决了问题:
SqlCommand myCommand = new SqlCommand();
myCommand.CommandTimeout = 150;
myCommand.CommandType = CommandType.Text;