为什么存储过程返回一个包含9列的表,使用此代码的89行需要60秒才能执行(.NET 1.1),这需要在SQL Server Management Studio中运行1秒钟的时间?它被在本地机器上运行,因此很少/没有网络延迟,快速dev的机器SqlDataAdapter.Fill方法缓慢
Dim command As SqlCommand = New SqlCommand(procName, CreateConnection())
command.CommandType = CommandType.StoredProcedure
command.CommandTimeout = _commandTimeOut
Try
Dim adapter As new SqlDataAdapter(command)
Dim i as Integer
For i=0 to parameters.Length-1
command.Parameters.Add(parameters(i))
Next
adapter.Fill(tableToFill)
adapter.Dispose()
Finally
command.Dispose()
End Try
我放慢参数数组类型(对于此SQL,这只是一个参数)
parameters(0) = New SqlParameter("@UserID", SqlDbType.BigInt, 0, ParameterDirection.Input, True, 19, 0, "", DataRowVersion.Current, userID)
存储的过程只喜欢一个select语句这样:
ALTER PROC [dbo].[web_GetMyStuffFool]
(@UserID BIGINT)
AS
SELECT Col1, Col2, Col3, Col3, Col3, Col3, Col3, Col3, Col3
FROM [Table]
这是一个古老的问题,许多人找到它。在开始清理缓存并使用ARITHABORT设置进行游戏之前,请阅读Erland Sommarskog的综合文章,该文章解释了可能发生的情况:[缓慢的应用程序,SSMS中的快速?了解性能之谜](http://www.sommarskog.se/query-plan-mysteries.html)很多时候,这种行为是由称为“参数嗅探”的SQL Server功能引起的。 – 2016-05-26 23:59:07