查询在查询分析器中运行得很快,但在 C# 应用程序中运行缓慢 [英] Query runs fast in Query Analyzer but slow in C# application

查看:28
本文介绍了查询在查询分析器中运行得很快,但在 C# 应用程序中运行缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
sql 在 ssms 中运行快在 asp.net 中慢

使用SQL Server 2005,有几个大表的sql查询,在程序中超时.但是,当我在查询分析器中运行它时,它会在大约 30 秒内完成.

Using SQL Server 2005, there is a sql query on a few big tables and it times out in the program. However, when I run it in Query Analyzer, it finishes in about 30 seconds.

为什么不同?

推荐答案

通常这些是 SET 设置差异,导致计划不同.在 Management Studio 中,该过程可能使用与创建时相同的设置相同运行.

Usually these are SET setting differences, leading to different plans. In Management Studio the procedure is probably running with the same settings as were in place when it was created.

查看您的 ASP.Net 应用程序和 SSMS 会话的 sys.dm_exec_sessions.我会猜测您的 SET 设置中至少有一个是不同的.这可能会导致不同的计划(最终这归因于参数嗅探)并且应用端通常会变得更糟.

Take a look at sys.dm_exec_sessions for your ASP.Net application and for your SSMS session. I will hazard a guess that at least one of your SET settings is different. This can contribute to different plans (ultimately this gets attributed to parameter sniffing) and the app side usually ends up worse off.

有关更多详细信息,请参阅这些其他问题:

See these other questions for a lot more details:

还阅读 Erland Sommarskog 的文章,应用程序慢,SSMS 快?

And also read Erland Sommarskog's article, Slow in the Application, Fast in SSMS?

这篇关于查询在查询分析器中运行得很快,但在 C# 应用程序中运行缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆