Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What causes Timeout expired SqlExceptions in LINQ to SQL?

My application keeps running into Timeout Expired SqlExceptions. The thing is that this query is one that will simply have to run for a decent amount of time. I'm having trouble figuring out where this exception is occurring though. Is this a timeout that's created at the database server or is it happening in my program? Or if it could be both, how do I figure out which one it is?

And lastly, how do I extend the timeout period?

like image 278
Jason Baker Avatar asked May 08 '09 15:05

Jason Baker


People also ask

What causes SQL timeout errors?

Typical causes and resolutions for the error For more tips and suggestions, see Troubleshooting: Timeout Expired. Server name was typed incorrectly. Try again with the correct server name. The SQL Server service on the server isn't running.

What is SQL timeout exception?

public class SQLTimeoutException extends SQLTransientException. The subclass of SQLException thrown when the timeout specified by Statement has expired. This exception does not correspond to a standard SQLState.


2 Answers

increase timeout = BAD
fix query = GOOD

I'm not sure of all the details involved, but in general the followng applies:

when a query runs slow do the following in management studio:

  • run SET ShowPlan_All ON
  • run your query
  • look at the output for the word "scan". your problem is there.

"Scan" = touch each row (table or index). Would you like to "scan" a phone book looking for one number or use the index?

like image 74
KM. Avatar answered Oct 10 '22 01:10

KM.


It is likely that you are running over the CommandTimeout set on your DataContext. This defaults to 30 seconds.

All you need to do is set the property on the DataContext before you execute your query.

like image 45
Garry Shutler Avatar answered Oct 10 '22 01:10

Garry Shutler