本文介绍了SqlDataSource的超时。在Management Studio中确定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在code,我继承,我有一个SqlDataSource,有一个相当复杂的select语句,对于某些SelectParameters,总是的超时(超时过期。超时时间之前执行完毕操作或服务器没有响应。)。

In code that I inherited, I have a SqlDataSource that has a fairly complex select statement that for certain SelectParameters, always times out ("Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.").

当我运行完全相同的查询与管理工作室相同的参数,查询的永远的超时,并始终以不到一秒。

When I run the exact same query with the same parameters in management studio, the query never times out and always takes less than a second.

有没有人有一个想法是什么这个问题可能是在这里吗?我无法理解它。

Does anyone have an idea what the problem could be here? I can't make sense of it.

推荐答案

在黑暗中只是一个镜头:该参数不实际上是相同的。在SSMS你传递ASCII参数查询,而在ADO.Net传递统一code的。 SqlCommand.Parameters.AddWithValue(@ myParam,myvalue的)将添加类型为nvarchar的参数时, myvalue的是一个串。由于SQL TE转换规则,如果你有 SELECT ... FROM ... WHERE MyField的= @myParam 和MyField的是ASCII(VARCHAR)和@myParam是统一code(NVARCHAR),则执行必须做一个表扫描,不能MyField的时候相比,SSMS执行使用索引,导致awfull性能。

Just a shot in the dark: The parameters are not actually the same. In SSMS you pass in ASCII parameters for the query, while in ADO.Net you pass Unicode ones. SqlCommand.Parameters.AddWithValue("@myParam", myValue) will add a parameter of type NVARCHAR when myValue is a String. Due to te conversion rules in SQL if you have SELECT ... FROM ... WHERE myField = @myParam and myField is Ascii (VARCHAR) and @myParam is Unicode (NVARCHAR) then the execution must do a table scan, cannot use an index on myField, resulting in awfull performance when compared to SSMS execution.

正如我所说的,这是在黑暗中只是一个镜头,但它是一个常见的​​错误和相当微妙的调试。

As I said, this is just a shot in the dark, but is a common pitfall and fairly subtle to debug.

这篇关于SqlDataSource的超时。在Management Studio中确定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 19:12