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

  • Home
  • SEARCH
  • 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 6476261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:48:13+00:00 2026-05-25T06:48:13+00:00

I have a parameter sniffing issue in sql server 2005 for a dynamic, parameterized

  • 0

I have a parameter sniffing issue in sql server 2005 for a dynamic, parameterized query that is generated in a C# client via ado.net and accessed in a web application from IIS using LocalSystem as the application pool’s identity.

When I run the query in SSMS it is very fast, but it times out after 30 seconds when run from the client, so I am certain of parameter sniffing.

Now, I want to look at the query plan for the query that is cached from the client, but I can’t seem to replicate the query in SSMS to use that cached plan.

I ran a trace and have the exact query, and all of the set parameters the client used, but this still does not give me the cached query plan when I run it in SSMS. I assume this has something to do with either the ApplicationName, NTUserName, or LoginName (also provided by the trace), but I am not sure which of these or which combination of these I need to set (or how to do it in SSMS) to run the query so that it uses the cached query plan.

  • 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. Editorial Team
    Editorial Team
    2026-05-25T06:48:13+00:00Added an answer on May 25, 2026 at 6:48 am

    get the query to run, then while it is running execute the follow script

    SELECT session_id, blocking_session_id, command, cpu_time, reads, writes, logical_reads, row_count, total_elapsed_time, granted_query_memory, DB_NAME(DATABASE_ID), 
    last_wait_type, wait_resource, start_time, open_transaction_count, query_plan, text
    FROM master.sys.dm_exec_requests (nolock) CROSS APPLY sys.dm_exec_query_plan(plan_handle) CROSS APPLY sys.dm_exec_sql_text(sql_handle)
    WHERE session_id <> @@SPID 
    

    this will return the estimated plan as well as other info of all currently running queries (you need VIEW SERVER STATE permission).

    Usually UPDATE STATISTICS would help you in this situations, or making your own statistics. If you’d like help with the query plan host the XML somewhere and i’ll be glad to help.

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

Sidebar

Related Questions

Today again, I have a MAJOR issue with what appears to be parameter sniffing
We're using SQL Server 2005 with Reporting Services. We have a number of reports,
I have a showall query string parameter in the url, the parameter is being
I have a method with an out parameter that tries to do a type
I have a const char arr[] parameter that I am trying to iterate over,
I have methods with more than one parameter that are guarded against bad input
I have a query from a web site that takes 15-30 seconds while the
I have SQL parameter array as... SqlParameter[] sqlParams = new SqlParameter[2]; If I want
I have a parameter in A1 that influences TOTAL in a random and very
I thought the difference is that declaration doesn't have parameter types... Why does this

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.