Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework - what is the current command timeout value

I'm using Entity Framework 5 and I wish to know the command timeout value.

In order to do so, I cast the dbContext object to an ObjectContext and I access the CommandTimeout property.

int ? currentCommandTimeout = ((IObjectContextAdapter)dbContext).ObjectContext.CommandTimeout; 

The current value of this property is null which means that the current command timeout is the default value of the underlying provider.

  1. Who is the underlying provider?
  2. How can I read (via EF code) the current command timeout value in this case?

MSDN ObjectContext CommandTimeout Property reference

EDIT: Thank you for explaining how to set the command timeout and finding the default command timeout value in the documentation. However, the question remains open. How, if possible, can you read the command timeout value in case of default, via EF.

like image 639
Oren Avatar asked Jun 11 '13 16:06

Oren


People also ask

What is command timeout?

CommandTimeout is how long a single command can take to complete. ConnectionTimeout is how long it can take to establish a connection to the server to start with.

What is maximum command timeout in C#?

SQL CommandTimeout will take only integer value and its maximum value is 32767 which is equal to 9 hours.

How do I set the execution 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; } } ...


1 Answers

From MSDN,

  • CommandTimeout property gets or sets the timeout value, in seconds, for all object context operations.
  • A null value indicates that the default value of the underlying provider will be used.

So, if you are not setting it explicitly through code or passing it in your connection string (in MySQL) , then it is the default value of your provider.

If you want to see a non-null value for CommandTimeout, then you will need to pass it in connectionString or set it through code.

Who is the underlying provider?

Underlying provider is the one you are passing in your connectionstring as providerName

<connectionStrings>   <clear />   <add name="Name"     providerName="System.Data.ProviderName"     connectionString="Valid Connection String;" /> </connectionStrings> 

Here, System.Data.ProviderName is your underlying provider.

If you are using MySql or MS Sql, According to the MySql Documentation and MSDN,

  • The default value is 30 secs.
  • A value of 0 indicates an indefinite wait and should be avoided.

    Note :

The default command timeout can be changed using the connectionstring attribute Default Command Timeout in case of MySQL database providers.

like image 166
Bhushan Firake Avatar answered Sep 25 '22 00:09

Bhushan Firake