Timeout issue using codefirststoredprocs in MVC5/EF 6. Error reading from stored proc dbo.[...]: Timeout expired

StackOverflow https://stackoverflow.com/questions/19944660

Question

In order to process nearly 70K records at a time, I use codefriststoredprocs 2.5.0 with my application. With few records everything works fine but with large set of data, I receive "The wait operation timed out" exception. I tried modifying default command timeout value from 30 seconds to 600 seconds in following manner.

//Previous approach
   ((System.Data.Entity.Infrastructure.IObjectContextAdapter)this.db).ObjectContext.CommandTimeout = 600;

//New approach for EF 6
this.db.Database.CommandTimeout = 600;

but still receives connection timeout message after 30 seconds. I also modified web.config setting Connection timeout value to 600 seconds (I know it is a different thing than command timeout value but give it a go). I feel like the issue is with codefirststoredprocs library that while executing stored procedure change command timeout value to default. Is there any way to fix this issue or should I go to alternate approach of using stored procedures with my application.

Thanks in advance.

Was it helpful?

Solution

First, I would like to thanks CodeFirstStoredProcs team for their effort and collaboration to solve this issue.

I guess, as mentioned earlier, the command timeout values might have been defaulted to 30 seconds inside CodeFirstStoredProcs library.

With their new release (version 2.6),they have added ‘command timeout’ parameter to the CallStoredProc<> method, that helped me set a default value for commandtimeout and finally solved my issue.

To process nearly 70K records in my case, I set CommandTimeout = 0 to CallStoredProc<> method. This adds an infinite waiting time to execute stored procedure.

Thanks once again for CodeFirstStoredProcs team. :)

OTHER TIPS

I got the same problem when changing to EF6.

Your might be setting the CommandTimeout in wrong place. Try setting the CommandTimeout where you are creating the context, like this:

var context = new Entities();
context.CommandTimeout = 600;

Also check if the CommandTimeout was changed with your approach after creating the context. If so then there might be some other issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top