简体   繁体   English

在VB.net中存储的proc超时,但在SSMS中快速运行

[英]Stored proc timeout in VB.net but runs quickly in SSMS

I have an issue I hope you can help with. 我有一个问题,希望您能提供帮助。

Developing an vb.net web app, using VS 2013 and SSMS. 使用VS 2013和SSMS开发vb.net Web应用程序。 I have a stored proc which runs very quickly when tested in SSMS. 我有一个存储的proc,当在SSMS中测试时,它运行非常快。 But, when I run an executenonquery in Visual Studio it takes forever, then times out. 但是,当我在Visual Studio中运行executenonquery时,它要花很长时间,然后超时。

What I've tried: To make sure it wasn't a connection related issue, etc... I created a super simple test stored proc with the same input params. 我尝试过的操作:为了确保这不是与连接有关的问题,等等。。。我创建了一个超级简单的测试存储过程,其输入参数相同。 The only code change I made was change from "StoredProcSlow" to "StoredProcTest". 我所做的唯一代码更改是从“ StoredProcSlow”更改为“ StoredProcTest”。 That's it. 而已。 This code ran perfectly fine in both SSMS and in Visual Studio. 该代码在SSMS和Visual Studio中都运行良好。 So, I know the vb.net code is fine. 因此,我知道vb.net代码很好。

Please note: The Input params of both stored procs (the original and my test) were exactly the same. 请注意:两个存储过程(原始测试和我的测试)的Input参数完全相同。

I can't try profiler because I'm using an Azure SQL Server database. 我无法使用探查器,因为我正在使用Azure SQL Server数据库。

Any ideas what could be the problem or how I can troubleshoot further? 有什么想法可能是问题,或者如何进一步排除故障?

UPDATE: I narrowed it down the the UPDATE of a specific table within the stored proc. UPDATE:我缩小了存储过程中特定表的UPDATE范围。 Even when I do a dummy update, such as "UPDATE dbo.Table1 SET DisplayName = 'XXXXX' WHERE (DisplayName = 'XXXXX')" it still hangs. 即使当我执行虚拟更新时,例如“ UPDATE dbo.Table1 SET DisplayName ='XXXXX'WHERE(DisplayName ='XXXXX')”,它仍然挂起。 Disabled all triggers. 禁用所有触发器。 Still hangs. 仍然挂起。 Any ideas appreciated. 任何想法表示赞赏。

UPDATE 2: I CLONED the offending Table1 into a test table (structure and data). 更新2:我将有问题的Table1克隆到测试表(结构和数据)中。 Then I used this new test table in the stored proc. 然后,我在存储的proc中使用了这个新的测试表。 It ran very good. 运行得很好。 This gets more confusing by the minute! 一分钟变得更加混乱!

The reason for significantly different performance is likely different execution plans. 性能显着不同的原因可能是不同的执行计划。 Run the query below to see if you have multiple cached plans for the same proc: 运行以下查询,以查看您是否对同一proc有多个缓存的计划:

SELECT  qs.plan_handle
      , qp.query_plan
FROM    sys.dm_exec_query_stats qs
        CROSS  APPLY sys.dm_exec_sql_text(qs.sql_handle) est
        OUTER APPLY sys.dm_exec_query_plan(qs.plan_handle) AS qp
WHERE   est.objectid = OBJECT_ID('dbo.your_proc');

Multiple plans may exist due to different session settings. 由于会话设置不同,可能存在多个计划。 The attributes that compose the key are described in the SQL Server Books Online ( https://msdn.microsoft.com/en-us/library/ms189472.aspx ). SQL Server联机丛书( https://msdn.microsoft.com/zh-cn/library/ms189472.aspx )中描述了构成键的属性。

For a thorough discussion on this topic, see Erland Sommarskog article: http://www.sommarskog.se/query-plan-mysteries.html . 有关此主题的详细讨论,请参见Erland Sommarskog文章: http : //www.sommarskog.se/query-plan-mysteries.html Note that not all the DMVs referenced in the article are available in Azure SQL Database but the basic concepts apply. 请注意,并非本文​​中引用的所有DMV都可在Azure SQL数据库中获得,但基本概念适用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM