none
EntityCommandExecutionException Timeout RRS feed

  • Question

  • Hi,

    I get the timeout error after only 30 seconds. I have it set below...

    try { internalEntities.CommandTimeout = (10 * 60); // set to 10mins

    internalEntities.Publish(ReportID); } catch (EntityCommandExecutionException entityCommandExecutionException) { Throw; }


    There is no timeout value set elsewhere in the code. Why is this timing out after 30secs?

    Thanks!

    Saturday, December 5, 2015 2:17 PM

Answers

  • I found the problem! In the EF model there was a class that contained the call to the stored proc!

    This uses EntityCommand, which is defaulted to 30secs!

    Thanks for the help!


    public void Publish()
    {
    
    EntityCommand publishEntityCommand = new EntityCommand
    {
        CommandType = CommandType.StoredProcedure,
        CommandText = @"InternalEntities.Publish",
        Connection = (EntityConnection)this.Connection
    };
    
    }
    
    

    • Edited by obrienkev Wednesday, December 9, 2015 3:45 PM
    • Marked as answer by obrienkev Wednesday, December 9, 2015 3:47 PM
    Wednesday, December 9, 2015 3:43 PM

All replies

  • Hi obrienkev,

    I reproduced your code on my side,it worked well .

    could you please share your internalEntities class code snippet and connectionstring  and exception message.

    Addtionally, you could check the database timeout settingthere may be a database timeout

    Best regards,




    Monday, December 7, 2015 9:28 AM
    Moderator
  • Hi,

    The code is wrapped in this using statement...

    using (InternalEntities internalEntities = new InternalEntities())


    Error: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

    Connectionstring:

    <add name="InternalEntities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=myDBServer;initial catalog=myDB;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

    No database timeout. The code calls a stored procedure, which takes 2mins to run when I call it from SSMS. And it runs without error in SSMS.

    Thanks.

    Monday, December 7, 2015 12:02 PM
  • Hi obrienkev,

    I reproduce your code on my side, it works well. The following is my code snippet with ef4. And I use ef5 and ef6, it also worked fine.

    using (BloggingEntities db=new BloggingEntities())
    {
          try
          {
              db.CommandTimeout = 60;
              foreach (var product in db.GetProductById2(2))
              {
                  Console.WriteLine(product.Id + "--" + product.Pro_Name);
              }
            }
            catch (EntityCommandExecutionException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex1)
            {
                 Console.WriteLine(ex1.Message);
            }
             Console.ReadKey();
          }          
     }
    

    The following is my store procedure.

    CREATE PROCEDURE [dbo].[GetProductById]
           @id int = 0
    AS
           waitfor delay '00:00:55'
           SELECT * from Product where Id = @id
    RETURN 0
    

    Are you use ef4? If possible, please has a try to upgrade to ef6 to see if the project work for you, and ef6 can make better use of stored procedures, as well as better performance

    Best regards,

    Cole
    Tuesday, December 8, 2015 6:42 AM
    Moderator
  • Yes. I am on EF4. Unfortunately for now I cannot upgrade to 6.

    The entity connection timeout is set at 15. I tried to increase this in the code but it's not allowed.

    Would this be an issue? However, it only timesout after 30secs. 

    Thanks.

    Wednesday, December 9, 2015 3:30 PM
  • I found the problem! In the EF model there was a class that contained the call to the stored proc!

    This uses EntityCommand, which is defaulted to 30secs!

    Thanks for the help!


    public void Publish()
    {
    
    EntityCommand publishEntityCommand = new EntityCommand
    {
        CommandType = CommandType.StoredProcedure,
        CommandText = @"InternalEntities.Publish",
        Connection = (EntityConnection)this.Connection
    };
    
    }
    
    

    • Edited by obrienkev Wednesday, December 9, 2015 3:45 PM
    • Marked as answer by obrienkev Wednesday, December 9, 2015 3:47 PM
    Wednesday, December 9, 2015 3:43 PM