执行客户端查询与 SSMS 中完全相同
我在 sql server 2005 中遇到一个动态参数化查询的参数嗅探问题,该查询通过 ado.net 在 C# 客户端中生成,并使用 LocalSystem 作为应用程序池的标识在 IIS 的 Web 应用程序中进行访问。
当我在 SSMS 中运行查询时,速度非常快,但从客户端运行时会在 30 秒后超时,因此我确信参数嗅探。
现在,我想查看从客户端缓存的查询的查询计划,但我似乎无法在 SSMS 中复制查询以使用该缓存计划。
我运行了跟踪并拥有准确的查询以及客户端使用的所有设置参数,但是当我在 SSMS 中运行它时,这仍然没有给我缓存的查询计划。我认为这与 ApplicationName、NTUserName 或 LoginName(也由跟踪提供)有关,但我不确定需要设置其中哪一个或它们的组合(或者如何在 SSMS 中进行设置)运行查询以便它使用缓存的查询计划。
I have a parameter sniffing issue in sql server 2005 for a dynamic, parameterized query that is generated in a C# client via ado.net and accessed in a web application from IIS using LocalSystem as the application pool's identity.
When I run the query in SSMS it is very fast, but it times out after 30 seconds when run from the client, so I am certain of parameter sniffing.
Now, I want to look at the query plan for the query that is cached from the client, but I can't seem to replicate the query in SSMS to use that cached plan.
I ran a trace and have the exact query, and all of the set parameters the client used, but this still does not give me the cached query plan when I run it in SSMS. I assume this has something to do with either the ApplicationName, NTUserName, or LoginName (also provided by the trace), but I am not sure which of these or which combination of these I need to set (or how to do it in SSMS) to run the query so that it uses the cached query plan.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让查询运行,然后在运行时执行以下脚本,
这将返回估计计划以及所有当前正在运行的查询的其他信息(您需要查看服务器状态权限)。
通常,更新统计信息会在这种情况下帮助您,或者进行您自己的统计。如果您需要有关查询计划的帮助,请将 XML 托管在某处,我将很乐意提供帮助。
get the query to run, then while it is running execute the follow script
this will return the estimated plan as well as other info of all currently running queries (you need VIEW SERVER STATE permission).
Usually UPDATE STATISTICS would help you in this situations, or making your own statistics. If you'd like help with the query plan host the XML somewhere and i'll be glad to help.