SQL query much slower running through app

I’ve run into an old problem – I have a stored proc that takes around 82 seconds to run through my web app.  However when I run it through SSMS it returns in about 3 seconds.  After poking around for a while it appears to be caused by SQL server parameter sniffing.  That’s where SQL server caches optimized execution plans based on parameter values – sometimes these plans can be bad…  So to fix it you specify “WITH RECOMPILE”:


From MS:


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s