Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Command Timeout in EF 6

I want to set command timeout for query execution, currently I am doing context.Database.CommandTimeout = 90; but i feel this is not working, I tried checking the process logs in database but found the time difference was always less than 90sec.

Can someone help how can I set the database timeout in Entity Framework 6?

like image 921
Ali Avatar asked May 02 '16 08:05

Ali


People also ask

How do I increase command timeout in Entity Framework?

Set database timeout in Entity Framework Try this on your context:...public class MyDatabase : DbContext { public MyDatabase () : base(ContextHelper. CreateConnection("Connection string"), true) { ((IObjectContextAdapter)this). ObjectContext. CommandTimeout = 180; } } ...

What is default timeout in Entity Framework?

Gets or sets the timeout value, in seconds, for all context operations. The default value is null, where null indicates that the default value of the underlying provider will be used.

What is command timeout in C#?

The CommandTimeout property sets or returns the number of seconds to wait while attempting to execute a command, before canceling the attempt and generate an error. Default is 30.


1 Answers

Check this :

Entity Framework 6 :

this.context.Database.CommandTimeout = 180;

Entity Framework 5:

((IObjectContextAdapter)this.context).ObjectContext.CommandTimeout = 180;

Entity Framework 4 and below:

this.context.CommandTimeout = 180;
like image 196
Dilip Oganiya Avatar answered Oct 23 '22 04:10

Dilip Oganiya