Increasing timeout for LINQ to SQL stored procedure call

linq-to-sql

Solution

On the DataContext, set the .CommandTimeout property to a much higher seconds value. The default for SQL Server is 30 seconds, and you can set it to 0 to have it not timeout.

Problem

I call a stored procedure via Linq-to-SQL. This stored procedure simply processes data that I've already inserted into another table. On large data sets, I get a timeout exception: ``` "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding." ``` I can't do anything to speed the stored procedure up -- it's just moving data from one table to another. I don't particularly want to increase the timeout in the database connection string -- this is the only thing that takes a long time. This isn't a web app; the stored procedure is called from a background thread in a normal Windows service. The background thread is kicked off by a WCF call, and the client periodically polls for the result of the background thread. Unfortunately, the stored procedure takes too long, and the `GetDataContext().spRunStoredProcedure()` call throws a `TimeoutException`, even though the stored procedure appears to be running fine. Can I increase the timeout just for this stored procedure call? Or is there a way to get the stored procedure to return "I'm not dead yet" to keep the connection from timing out?

Original source