Home Software Consultant

LINQ-SQL, Contains, Bug

2010-09-19T15:17:47+00:00

Recently, client had reported a strange bug, which I had never encountered before. The client was editing value of an int column in a gridview. Once the value was changed, the grid displayed this error -The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Too many parameters were provided in this RPC request. The maximum is 2100. Now, we were not calling any stored procedure. My colleague found the cause of this problem. We were updating an enitity on cell changed event. To update, we were first making a select query like this, List cs = (from cl in Dataclass.Consumers where (cl.ID == ID) && draUmList.Select(f => f.Order).Contains(cl.ID) select cl).ToList(); The above query was getting converted into exec sp_executesql N'SELECT xyx AS [t0] WHERE (id] IN (@p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12, @p13, @p14, @p15, @p16, @p17, @p18, @p19, @p20, @p21, @p22, @p23, @p24, @p25, @p26, @p27, @p28, @p29, @p30, @p31, @p32, @p33, @p34, @p35, @p36, @p37, @p38, @p39, @p40, @p41, @p42, @p43, @p44, @p45, @p46, @p47, @p48, @p49, @p50, @p51, @p52, @p53, @p54, @p55, @p56, @p57, @p58, @p59, @p60, @p61, @p62, @p63, @p64, @p65, @p66, @p67, @p68, @p69, @p70, @p71, @p72, @p73, @p74, @p75, @p76, @p77, @p78, @p79, @p80, @p81, @p82, @p83, @p84, @p85, @p86, @p87, @p88, @p89, @p90, @p91, @p92, @p93, @p94, @p95, @p96, @p97, @p98, @p99, @p100, @p101, @p102, @p103, @p104, @p105, @p106, @p107, @p108, @p109, @p110, @p111, @p112, @p113, @p114, @p115, @p116, @p117, @p118, @p119, @p120, @p121, @p122, @p123, @p124, @p125, @p126, @p127, @p128, @p129, @p130, @p131, @p132, @p133, @p134, @p135, @p136, @p137, @p138, @p139, @p140, @p141, @p142, @p143, @p144, @p145, @p146, @p147, @p148, @p149))',N'@p0 uniqueidentifier,@p1 uniqueidentifier,@p2 uniqueidentifier,@p3 uniqueidentifier,@p4 uniqueidentifier,@p5 uniqueidentifier,@p6 uniqueidentifier,@p7 uniqueidentifier,@p8 uniqueidentifier,@p9 uniqueidentifier,@p10 uniqueidentifier,@p11 uniqueidentifier,@p12 uniqueidentifier,@p13 uniqueidentifier,@p14 uniqueidentifier,@p15 uniqueidentifier,@p16 uniqueidentifier,@p17 uniqueidentifier,@p18 uniqueidentifier,@p19 uniqueidentifier,@p20 uniqueidentifier,@p21 uniqueidentifier,@p22 uniqueidentifier,@p23 uniqueidentifier,@p24 uniqueidentifier,@p25 uniqueidentifier,@p26 uniqueidentifier,@p27 uniqueidentifier,@p28 uniqueidentifier,@p29 uniqueidentifier,@p30 uniqueidentifier,@p31 uniqueidentifier,@p32 uniqueidentifier,@p33 uniqueidentifier,@p34 uniqueidentifier,@p35 uniqueidentifier,@p36 uniqueidentifier,@p37 uniqueidentifier,@p38 uniqueidentifier,@p39 uniqueidentifier,@p40 uniqueidentifier,@p41 uniqueidentifier,@p42 uniqueidentifier,@p43 uniqueidentifier,@p44 uniqueidentifier,@p45 So, if there too many instances of the entity, it could easily exceed 2100. So, the solution which replaced the above query, used join query and where clause, which was more efficient.