title: .NET SqlClient - Timeout expired
body: <p>Currently i am building an query on a database in .net core. One of the querys has many different filters like the following example:</p>
  <pre><code>IQueryable&lt;OperatingInstructionDTO&gt; newQuery = this.Database.Set&lt;OperatingInstructionDTO&gt;()
                  .Include(x =&gt; x.CurrentState)
                  .Include(x =&gt; x.Plant)
                  .Include(x =&gt; x.Department)
                  .Include(x =&gt; x.Creator)
                  .Where(x =&gt; x.Type != null &amp;&amp; x.Type.Equals(type) &amp;&amp; x.Department.Id == user.Department.Id);
  
              
              if (filter.InstructionTitle != null)
                  newQuery = newQuery.Where(x =&gt; x.Title.Contains(filter.InstructionTitle));
  
              if (filter.SelectedStates != null)
                  newQuery = newQuery.Where(x =&gt; filter.SelectedStates.Contains(x.CurrentState.Description));
  
              if (filter.SelectedEditors != null &amp;&amp; filter.SelectedEditors.Count == 1)
              {
                  if (filter.SelectedEditors[0].Equals(&quot;Eigene&quot;))
                      newQuery = newQuery.Where(x =&gt; x.Creator.Email.Equals(user.Email));
                  else
                      newQuery = newQuery.Where(x =&gt; !x.Creator.Email.Equals(user.Email));
              }
  
              if (filter.OverallTextFilter != null)
                  newQuery = newQuery.Where(x =&gt;x.Content!=null &amp;&amp; x.Content.Contains(filter.OverallTextFilter));
  
              newQuery = newQuery.OrderByDescending(x =&gt; x.CreationTimestamp).ThenBy(x =&gt; x.Title).Take(filter.SelectedNumberOfResults);
  
              return newQuery.Select(x =&gt; new OperatingInstructionDTO
              {
                  CreationTimestamp = x.CreationTimestamp,
                  CurrentState = x.CurrentState,
                  Department = x.Department,
                  ParentOperatingInstruction = new OperatingInstructionDTO
                  {
  
                  },
                  Plant = x.Plant,
                  Title = x.Title,
                  Id = x.Id,
                  Creator = x.Creator,
                  Type = x.Type
              }).ToList();
  </code></pre>
  <p>If i set the filter <strong>OverallTextFilter</strong> the execution is very slow. I know this but this feature is needed for the customer. Because the exection is so slow i get the following error message:</p>
  <pre><code>System.Data.SqlClient.SqlException
    HResult=0x80131904
    Message=Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
    Source=Core .Net SqlClient Data Provider
    StackTrace:
     at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
     at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
     at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
     at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean&amp; dataReady)
     at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
     at System.Data.SqlClient.SqlDataReader.get_MetaData()
     at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
     at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task&amp; task, Boolean asyncWrite, SqlDataReader ds)
     at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task&amp; task, Boolean asyncWrite, String method)
     at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
     at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
     at System.Data.Common.DbCommand.ExecuteReader()
     at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
     at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
     at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
     at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
     at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
     at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
     at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.&lt;_TrackEntities&gt;d__17`2.MoveNext()
     at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
     at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
     at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
     at ModulareArbeitsanweisung.Database.Wrapper.InstructionManager.ReadOperationInstructionsWithFilter(UserDTO user, String type, InstructionFilter filter) in C:\Users\adlerlu\Desktop\CUE_GIT_REPO\SWP-Core-Backendservices\Modulare Arbeitsanweisung\ModulareArbeitsanweisung\ModulareArbeitsanweisung\Database\Wrapper\InstructionManager.cs:line 119
     at ModulareArbeitsanweisung.Controllers.InstructionController.List(InstructionFilter filter) in C:\Users\adlerlu\Desktop\CUE_GIT_REPO\SWP-Core-Backendservices\Modulare Arbeitsanweisung\ModulareArbeitsanweisung\ModulareArbeitsanweisung\Controllers\InstructionController.cs:line 64
     at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
     at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
     at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.&lt;InvokeActionMethodAsync&gt;d__12.MoveNext()
  
  Inner Exception 1:
  Win32Exception: Der Wartevorgang wurde abgebrochen
  </code></pre>
  <p>How can i fix this?</p>