Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 121089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:54:53+00:00 2026-05-11T03:54:53+00:00

How could a stored procdure run in 10 seconds via Management Studio, but take

  • 0

How could a stored procdure run in 10 seconds via Management Studio, but take 15 minutes via a TableAdapter for the same inputs? It is repeatable, meaning I have run it at least three times in each environment, and Management Studio is consistently about 100 times faster.

I’m using .net 2.0 and SQL Server 2000

In SQL Server Management, I’m executing it like this:

EXEC    [dbo].[uspMovesReportByRouteStep]     @RouteStep = 12000,     @RangeBegin = N'12/28/08',     @RangeEnd = N'1/18/9' 

In the TableAdapter, I’m using a StoredProcedure CommandType and dbo.uspMovesReportByRouteStep for the CommandText. I’m calling the table adapter from an ASP.NET page, although it times out in 30 seconds if I attempt to ‘Preview Data’ locally too.

It’s not practical to provide the stored procedure because it’s over 100 lines long with dependencies on a number of other UDFs and views on the same and other databases.

All other stored procedures appear to run in about the same time using either method. How is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T03:54:53+00:00Added an answer on May 11, 2026 at 3:54 am

    This is very likely due to ‘parameter sniffing’ and a cached query plan that is not appropriate for the particular values of the parameters you are calling it with. How does that happen? Well, the first time you call a SP with one set of values, a query plan will be generated, parameterised and cached. If the SP is called again with another set of parameter values that would have resulted in a different query plan, but it uses the cached query plan, then performance can suffer.

    It is often because statistics are out of date. You can determine if that’s the case by comparing the Estimated execution plan against the Actual execution plan; if different then statistics are most likely out of date.

    I would first try and get the Database’s indexes rebuilt, or at least it’s statistics updated (ask your DBA). One way to rebuild the indexes (should work on all versions on SQL Server):

    exec sp_msforeachtable 'dbcc dbreindex ('?')' 

    If it’s still a problem, try temporarily adding the statement WITH RECOMPILE to the stored procedure definition. If the problem goes away, then take a look at using OPTIMIZE FOR, described in this blog post.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that executes much faster from Sql Server Management Studio
Could anyone point exactly where MSDN says thet every user stored procedure returns 0
I need a database that could be stored network drive and would allow multiple
I have fname and lname in my database, and a name could be stored
I have values stored as strings in a DataTable where each value could really
I am fairly new to stored procedures. I naively thought that I could build
I have a big stored procedure that I run. At the end its supposed
Referring to How to execute an Oracle stored procedure via a database link ,
I have an SP that takes 10 seconds to run about 10 times (about
I have a problem where it seems that when running the same stored procedure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.