Monday, August 01, 2011

Entity Framework and Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

I had troubles with long list in "delete" action. After several unsuccessful attempts I found solution (maybe is not the best):

using (var ctx = new EntityContext())
{
  var tmpTimeout = ctx.CommandTimeout;
  try
  {
   ctx.CommandTimeout = int.MaxValue;
   ctx.YOUROBJECTS.DeleteObject(value));
   ctx.SaveChanges();
  }
  catch (Exception ex)
  {}
  finally
  {
   ctx.CommandTimeout = tmpTimeout;
  }
}

No comments: