简体   繁体   中英

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. I have a stored proc which runs very quickly when tested in SSMS. But, when I run an executenonquery in Visual Studio it takes forever, then times out.

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". That's it. This code ran perfectly fine in both SSMS and in Visual Studio. So, I know the vb.net code is fine.

Please note: The Input params of both stored procs (the original and my test) were exactly the same.

I can't try profiler because I'm using an Azure SQL Server database.

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. Even when I do a dummy update, such as "UPDATE dbo.Table1 SET DisplayName = 'XXXXX' WHERE (DisplayName = 'XXXXX')" it still hangs. Disabled all triggers. Still hangs. Any ideas appreciated.

UPDATE 2: I CLONED the offending Table1 into a test table (structure and data). Then I used this new test table in the stored 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:

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 ).

For a thorough discussion on this topic, see Erland Sommarskog article: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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