0

I have a C# webform that uses a gridview bound to an EntityDataSource.
Now when I run an extensive query I get a timeout on the underlying sql query.

Anyone knows how to set the query timeout using EntityDataSource?

I found a few articles that state how to do that with a SqlDataSource but not with EntityDataSource.

Thank you.

Edoardo
  • 95
  • 10

1 Answers1

0

You could set the timeout using the connectionstring.

From msdn How to: Define the Connection String

<connectionStrings>
    <add name="AdventureWorksEntities"
    connectionString="metadata=.\AdventureWorks.csdl|.\AdventureWorks.ssdl|.\AdventureWorks.msl;
    provider=System.Data.SqlClient;provider connection string='Data Source=localhost;
    Initial Catalog=AdventureWorks;Integrated Security=True;Connection Timeout=60;
    multipleactiveresultsets=true'" providerName="System.Data.EntityClient" />
</connectionStrings>

Note the relevant part:

Connection Timeout=60;

Edit:

I just read here there is a known bug when you set the TimeOut in the Entity Framework ConnectionString. So you might want to set the TimeOut directly on the context as noted in the answer.

this.context.CommandTimeout = 60;

Or:

((IObjectContextAdapter)this.context).ObjectContext.CommandTimeout = 60;
Community
  • 1
  • 1
Jos Vinke
  • 2,704
  • 3
  • 26
  • 45