dcsimg
Results 1 to 7 of 7

Thread: [RESOLVED] Entity Framework timeout exception

  1. #1

    Thread Starter
    Fanatic Member cory_jackson's Avatar
    Join Date
    Dec 2011
    Location
    Fallbrook, California
    Posts
    858

    Resolved [RESOLVED] Entity Framework timeout exception

    I moved my Db to Azure and now some of the big table fills take longer. If longer than about 36 seconds I get:
    InnerException = {"Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding."}
    I found objContext.Database.ConnectionTimeout but it doesn't seem to be the correct parameter. Where can I increase the timeout for such an action?

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,018

    Re: Entity Framework timeout exception

    Entity Framework is built on top of ADO.NET. In ADO.NET, the DbConnection class (base class for SqlConnection, OleDbConnection, etc) has a ConnectionTimout property that specifies how long to wait when you call Open before throwing an exception. That is set to 30 seconds by default. The property you mentioned maps to that. The DbCommand class (base class for SqlCommand, OleDbCommand, etc) has a CommandTimeout property that specifies how long to wait when you call ExecuteReader or the like before throwing an exception. That is also set to 30 seconds by default. Not surprisingly, that would map to 'objContext.Database.CommandTimeout' in your scenario. I have code that sets that property to 7200 (2 hours) for a large, complex export routine.

  3. #3

    Thread Starter
    Fanatic Member cory_jackson's Avatar
    Join Date
    Dec 2011
    Location
    Fallbrook, California
    Posts
    858

    Re: Entity Framework timeout exception

    Thanks buddy. I tried that but it didn't work. I'll try again.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,018

    Re: Entity Framework timeout exception

    Like I said, the default is 30 seconds. That's why you're seeing an exception thrown after a bit over 30 seconds. If you increase CommandTimeout and it takes longer to throw the exception then it is working in that it is waiting longer, but it's still not waiting long enough for the command to complete or the command just won't complete for some reason. It definitely works as it was critical to a fix I made to an application recently.

  5. #5

    Thread Starter
    Fanatic Member cory_jackson's Avatar
    Join Date
    Dec 2011
    Location
    Fallbrook, California
    Posts
    858

    Re: Entity Framework timeout exception

    It has been strange. I have a stopwatch in there and successes have been as high as 36 seconds. But the failures have been as high as 2 minutes. I would think if it timed out at 30 seconds, my stopwatch would show slightly more than 30 seconds for each exception.

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,018

    Re: Entity Framework timeout exception

    Are you sure that only one command is being executed? If there are multiple then it may be a different one that times out each time. You could use SQL Profiler to see exactly what was being executed for a local SQL Server instance. Not sure whether you can use the same or similar tool for Azure, although I'd expect that there's something.

  7. #7

    Thread Starter
    Fanatic Member cory_jackson's Avatar
    Join Date
    Dec 2011
    Location
    Fallbrook, California
    Posts
    858

    Re: Entity Framework timeout exception

    objContext.Database.CommandTimeout = 1000
    I added this and it's working reliably. I mist have messed something else up the time before to make me think it wasn't working.
    Thank you sir.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width