Business Technology Times, a division of NTERDEV. LLC

Business Technology Times – the latest in business and affordable internet technology…

Stored Procedure runs in SQL Server Management Studio, but Timeout in .NET call

12.09.2011 (8:07 am) – Filed under: ASP.Net, SQL Server ::

I ran into a really strange issue that is worth mentioning. There was an existing system that had been running fine for over two years now and suddenly began to timeout in 30 seconds from an ASP.Net web page. I was asked to look into it. I took a look and began tracing through it. It gave the following error “Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.”. The .Net page was using LINQ to SQL. So I extended the timeout on the connection and command side and still received the same error. I then ran a similation of the stored procedure call in SQL Server Management Studio, passing in the same parameters. The results were returing quickly within one second. I thought his was odd and began to wonder if there was some issue with LINQ to SQL. So I created an ADO.Net version of running the remote procedure call to the stored procedure and surprisingly received the same error. I began to think there must have been a change to permission or network configuration. The server engineers explained there were no changes. I asked to receive a copy of the database to run locally. Running againts the local database I received the same error. I lauched the SQL Server Profiler to view the actual steps taking place when running from .Net compared to running it directly in SQL Server Management Studio. The difference was the remote procedure call classification. After doing some research, I found that with complex stored procedures doing aggregations, if there isn’t an adaquate maintenance plan for index rebuilding and updating statistics then you could run into and issue with remote procedure calls. So if you don’t have access to adjust maintenance plans on production servers, you can add the following two lines of code to your stored procedure and it will fix the timeout error from when running in .Net.

Step 1
Towards the beginning of the stored procedure you should add the line, “SET ARITHABORT ON;”.
When running stored procedure call in .NET, the arithabort option disabled by default, but it’s enabled by default in when running in SQL Server Management Studio. The result is that the server actually caches 2 separate execution plans for most/all procedures. This affects how the server performs numerical calculations and as such you can get wildly different results depending on the procedure.

Step 2
At the end of your select statement you should add the line, “OPTION(RECOMPILE)”.
This statement will force a seek to obtain potentially faster execution plan for the stored procedure. This explicit call helps if you are unsure about what maintenance plan you have in place and how often it is run. I would say this statement should be used on an as needed basis, such as a scenario like the one described above.

This was a very unique scenario that came up, and there is not much out there talking about this and pulling it all together. Hope this is helpful to someone.

Regards,

Brian McCumber (Find me on Twitter: @nterdev)
NTERDEV, LLC

Popularity: 1% [?]

All I can say is wow! It’s ju…

09.11.2010 (9:13 am) – Filed under: Brian McCumber ::

All I can say is wow! It’s just the beginning. China downgrades buying US debt. Read this article just released - http://bit.ly/9UOTfq

Popularity: 15% [?]

Silver is still going up! Infl…

09.11.2010 (8:51 am) – Filed under: Brian McCumber ::

Silver is still going up! Inflation is beginning. I share as a friend. Protect your savings. Get out of dollars. Watch http://bit.ly/dvyUsF

Popularity: 13% [?]

Day two after Fed decides to p…

05.11.2010 (12:04 pm) – Filed under: Brian McCumber ::

Day two after Fed decides to print $600 Billion new dollars, Silver shoots up another 2.79% in one day. It’s only the beginning…

Popularity: 13% [?]

Get the edge on SocialMedia! P…

05.11.2010 (11:07 am) – Filed under: Brian McCumber ::

Get the edge on SocialMedia! PostRank, a social media analytics service automates reader engagement statistics. http://www.postrank.com/

Popularity: 14% [?]

One day after Fed decided to p…

04.11.2010 (12:00 pm) – Filed under: Brian McCumber ::

One day after Fed decided to print more money, Silver is up 7.18% in one day! In Chicago you can buy Silver here - http://bit.ly/asi88l

Popularity: 13% [?]

This is pretty cool! Nudgemai…

04.11.2010 (10:10 am) – Filed under: Brian McCumber ::

This is pretty cool! Nudgemail, the easiest way to send yourself reminders. Check it out at http://www.nudgemail.com

Popularity: 13% [?]

Awesome deal at Tiger Direct f…

03.11.2010 (10:18 am) – Filed under: Brian McCumber ::

Awesome deal at Tiger Direct for new desktop pc. Bundle includes AMD CPU,2GB,500GB,DVDRW,Case & PS - Visit http://bit.ly/cXJoZq

Popularity: 13% [?]

In a few minutes, Fed’s decisi…

03.11.2010 (9:58 am) – Filed under: Brian McCumber ::

In a few minutes, Fed’s decision on printing more money. Hope you had a chance to move your dollars into gold/silver…

Popularity: 13% [?]

Now you can find and interview…

02.11.2010 (12:20 pm) – Filed under: Brian McCumber ::

Now you can find and interview experts, celebrities and other fascinating people with Listorious. Visit http://www.Listorious.com

Popularity: 13% [?]