Strange problem with SQL Server 2005 Stored procedure performing the same SELECT many, many times

I have a weird problem. Let me give you some information.

There is a stored procedure that has a single selection that returns a dataset and a return value of 0.

Before the "main" selection in sp, also the fake selection (due to SSIS and codegen tools) looks like this:


IF (1=0)
BEGIN
 CONVERT(INT, NULL) AS Id
 ,CONVERT(VARCHAR(50), NULL) AS someColumn
        ,...
END

      

There's one latest release from the usual - the basic selection construct uses the "TOP" keyword with an integer variable instead of a scalar value. Looks like:


SELECT TOP (@top)
...
...
FROM
...

      

Now before the problem: when the procedure is called from SSMS directly, it runs within a few ms. When called from an application, it starts up after a few minutes. We discovered through SQL Profiler that the "main" selection within a procedure is called thousands of times when the procedure is called from within an application (we are using the MS Enterprise SqlDatabase object library, ExecuteReader method, .NET 2.0 approach).

The point is that our application calls hundreds of other procedures without any similar problems for many years. So, I hope that someone has the knowledge that we are missing.

+2


a source to share


1 answer


DECIDE!

However, I don't understand. Seems to be a dynamic SQL problem (TOP clause). I removed the dynamic syntax as per this article and it worked (at least so far).



If someone can clear it up for me, the question is still there.

+3


a source







All Articles