Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

We are currently experiencing a problem with Entity Framework which generates a sp_executesql statement. This statement is below. The statement runs fine in SQL Server however through the front end this just causes the application to hang.

Further to this other parameters with the same query run fine. The only way we have managed to get the system working again using the original parameter is to run sp_refreshview which makes no sense as the underlying tables haven't changed and also the query runs fine in SQL Server.

Does anyone have any ideas what may be causing this?

exec sp_executesql N'SELECT TOP (1) 
[Project1].[Id] AS [Id], 
[Project1].[WorkCentreId] AS [WorkCentreId], 
[Project1].[WorksOrderId] AS [WorksOrderId], 
[Project1].[Operator] AS [Operator], 
[Project1].[BookingDate] AS [BookingDate], 
[Project1].[StartTime] AS [StartTime], 
[Project1].[Duration] AS [Duration], 
[Project1].[TotalProduced] AS [TotalProduced], 
[Project1].[RejectQty] AS [RejectQty], 
[Project1].[Item] AS [Item], 
[Project1].[Mould] AS [Mould], 
[Project1].[BatchCode] AS [BatchCode], 
[Project1].[Complete] AS [Complete], 
[Project1].[Status] AS [Status], 
[Project1].[ShiftId] AS [ShiftId], 
[Project1].[EndDateTime] AS [EndDateTime], 
[Project1].[DataAreaId] AS [DataAreaId]
FROM ( SELECT 
      [Extent1].[Id] AS [Id], 
      [Extent1].[WorkCentreId] AS [WorkCentreId], 
      [Extent1].[WorksOrderId] AS [WorksOrderId], 
      [Extent1].[Operator] AS [Operator], 
      [Extent1].[BookingDate] AS [BookingDate], 
      [Extent1].[StartTime] AS [StartTime], 
      [Extent1].[Duration] AS [Duration], 
      [Extent1].[TotalProduced] AS [TotalProduced], 
      [Extent1].[RejectQty] AS [RejectQty], 
      [Extent1].[Item] AS [Item], 
      [Extent1].[Mould] AS [Mould], 
      [Extent1].[BatchCode] AS [BatchCode], 
      [Extent1].[Complete] AS [Complete], 
      [Extent1].[Status] AS [Status], 
      [Extent1].[ShiftId] AS [ShiftId], 
      [Extent1].[EndDateTime] AS [EndDateTime], 
      [Extent1].[DataAreaId] AS [DataAreaId]
      FROM [dbo].[vw_BookingHistory] AS [Extent1]
      WHERE [Extent1].[WorkCentreId] = @p__linq__0
)  AS [Project1]
ORDER BY [Project1].[EndDateTime] DESC',N'@p__linq__0 nvarchar(4000)',@p__linq__0=N'QK0009'
share|improve this question
    
Is [Extent1].[WorkCentreId] of type varchar(4000)? If not, it's probably doing a table scan. If there are a lot of records in Extent1, then this could be slow. –  David Crowell Mar 17 '14 at 17:26
    
How many records are in the view (vw_BookingHistory)? How complex is the view's query? –  Adam Zuckerman Mar 18 '14 at 3:33
2  
Can you post the execution plan from when it's having a problem and from when it's working fine? –  mrdenny Mar 18 '14 at 6:19
    
Please see the links the plans although they look the same to me. dl.dropboxusercontent.com/u/11680929/Plans/… dl.dropboxusercontent.com/u/11680929/Plans/WorkingPlan.sqlplan –  Tom Mar 18 '14 at 10:23
    
What happens when you add the suggested missing index? USE [ProductionDashboard] GO CREATE NONCLUSTERED INDEX [<Name of Missing Index, sysname,>] ON [dbo].[PRODTABLE] ([PRODID]) INCLUDE ([ITEMID],[NAME],[DATAAREAID]) GO –  Mark Sinkinson Mar 18 '14 at 10:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.