title: Entity Framework 4 Stored Procedure Call Timing Out
body: <p>I have a stored procedure imported into EF4, and when I call it with certain parameters after 30 seconds it throws a time out error. In SQL Server profiler I can see the stored procedure call with the proper parameters taking just over 30 seconds, which is the timeout on my application. </p>
  
  <p>HOWEVER when I execute the same SQL sent to the profiler in Query Analyzer it executes sub-second. What could cause this discrepancy between being called from EF and being called from SQL Server Management Studio?</p>
  
  <p>Full stack trace of .NET error bellow.</p>
  
  <blockquote>
    <p>[SqlException (0x80131904): Timeout expired.  The timeout period
    elapsed prior to completion of the operation or the server is not
    responding.]<br>
    System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
    Boolean breakConnection) +2073486<br>
    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
    exception, Boolean breakConnection) +5064444<br>
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234<br>
    System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
    SqlCommand cmdHandler, SqlDataReader dataStream,
    BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
    stateObj) +2275<br>
    System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33<br>
    System.Data.SqlClient.SqlDataReader.get_MetaData() +86<br>
    System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,
    RunBehavior runBehavior, String resetOptionsString) +311<br>
    System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
    cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean
    async) +987<br>
    System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
    cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
    method, DbAsyncResult result) +162<br>
    System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
    cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
    method) +32<br>
    System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
    behavior, String method) +141<br>
    System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior
    behavior) +12<br>
    System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
    +10    System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand
    entityCommand, CommandBehavior behavior) +443</p>
    
    <p>[EntityCommandExecutionException: An error occurred while executing
    the command definition. See the inner exception for details.]<br>
    System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand
    entityCommand, CommandBehavior behavior) +479<br>
    System.Data.Objects.ObjectContext.CreateFunctionObjectResult(EntityCommand
    entityCommand, EntitySet entitySet, EdmType edmType, MergeOption
    mergeOption) +182<br>
    System.Data.Objects.ObjectContext.ExecuteFunction(String functionName,
    MergeOption mergeOption, ObjectParameter[] parameters) +218<br>
    System.Data.Objects.ObjectContext.ExecuteFunction(String functionName,
    ObjectParameter[] parameters) +53<br>
    MetaView.DAL.MFCMData.MFCMDATAEntities.GetTradingOpenPositionCounterParty(Nullable<code>1
    positionDT, Nullable</code>1 tradingAccountID) in
    C:\Projects\CASH\web\MetaView\MetaView.DAL.MFCMData\MFCMData.Designer.cs:7064
    MetaView.BusinessLayer.Shared.Accounts.CounterParties.GetCounterParties(Int32
    tradingAccountID) in
    C:\Projects\CASH\web\MetaView\MetaView.BusinessLayer\Shared\Accounts\CounterParties.cs:161</p>
  </blockquote>