Note that there are some explanatory texts on larger screens.

plurals
  1. POPoor SP performance from ASP.NET
    primarykey
    data
    text
    <p>I have a stored procedure that handles sorting, filtering and paging (using Row_Number) and some funky trickery :) The SP is running against a table with ~140k rows.</p> <p>The whole thing works great and for at least the first few dozen pages is super quick. However, if I try to navigate to higher pages (e.g. head to the last page of 10k) the whole thing comes to a grinding halt and results in a SQL timeout error.</p> <p>If I run the same query, using the same parms inside studio manager query window, the response is instant irrespective of the page number I pass in.</p> <p>At the moment it's test code that is simply binding to a ASP:Datagrid in .NET 3.5</p> <p>The SP looks like this:</p> <pre><code>BEGIN WITH Keys AS ( SELECT TOP (@PageNumber * @PageSize) ROW_NUMBER() OVER (ORDER BY JobNumber DESC) as rn ,P1.jobNumber ,P1.CustID ,P1.DateIn ,P1.DateDue ,P1.DateOut FROM vw_Jobs_List P1 WHERE (@CustomerID = 0 OR CustID = @CustomerID) AND (JobNumber LIKE '%'+@FilterExpression+'%' OR OrderNumber LIKE '%'+@FilterExpression+'%' OR [Description] LIKE '%'+@FilterExpression+'%' OR Client LIKE '%'+@FilterExpression+'%') ORDER BY P1.JobNumber DESC ),SelectedKeys AS ( SELECT TOP (@PageSize)SK.rn ,SK.JobNumber ,SK.CustID ,SK.DateIn ,SK.DateDue ,SK.DateOut FROM Keys SK WHERE SK.rn &gt; ((@PageNumber-1) * @PageSize) ORDER BY SK.JobNumber DESC) SELECT SK.rn ,J.JobNumber ,J.Description ,J.Client ,SK.CustID ,OrderNumber ,CAST(DateAdd(d, -2, CAST(isnull(SK.DateIn,0) AS DateTime)) AS nvarchar) AS DateIn ,CAST(DateAdd(d, -2, CAST(isnull(SK.DateDue,0) AS DateTime)) AS nvarchar) AS DateDue ,CAST(DateAdd(d, -2, CAST(isnull(SK.DateOut,0) AS DateTime)) AS nvarchar) AS DateOut ,Del_Method ,Ticket# ,InvoiceEmailed ,InvoicePrinted ,InvoiceExported ,InvoiceComplete ,JobStatus FROM SelectedKeys SK JOIN vw_Jobs_List J ON j.JobNumber=SK.JobNumber ORDER BY SK.JobNumber DESC END </code></pre> <p>And it's called via </p> <pre><code>sp_jobs (PageNumber,PageSize,FilterExpression,OrderBy,CustomerID) </code></pre> <p>e.g.</p> <pre><code>sp_Jobs '13702','10','','JobNumberDESC','0' </code></pre> <p>Can anyone shed any light on what might be the cause of the dramatic difference in performance between SQL query window and an asp.net page executing a dataset?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload