views:

1314

answers:

4

A search query returned this error. I have a feeling its because the in clause is ginormous on a subordinant object, when I'm trying to ORM the other object.

Apparently in clauses shouldn't be built 1 parameter at a time. Thanks ibatis.

+4  A: 

Your best bet is to revise your application to pass less than 2100 parameters to the stored procedure. This is a DBMS limit that can't be raised.

JP Alioto
+3  A: 

You can do a few things:

  1. Pump the params into a temp table and use said temp table to filter your query.
  2. Create a comma-delimited array, and pass the array into SQL Server as a varchar(x). Split it out via TSQL (here are a few methods) and use the resulting rowset to filter your search results.
  3. Have a look at your application logic. It's more than a little strange to be passing 2100 parameters to a stored procedure.
Aaron Alton
+3  A: 

If you are passing 2100 parameters to a single stored procedure, you are simply doing something wrong. Don't raise the limit or try to work around this abomination, figure out how to do things right.

Mark Brittingham
+3  A: 

I got this same error when using an apparently innocent LINQ to SQL query. I just wanted to retrieve all the records whose ids were amongst the ones stored in an array:

dataContext.MyTable.Where(item => ids.Contains(item.Id)).ToArray();

It turned out that the ids array had more than 2100 items, and it seems that the DataContext adds one parameter for each item in the array in the resulting SQL query.

At the end it was a bug in my code, since the ids array had not to have so many items. But anyway it is worth to keep in mind that some extra validation is needed when using such constructs in LINQ to SQL.

Konamiman
thank you for validating the question, I would love if you upvote it, since you ran into it and it will clearly be helpful to others for it to stay in the search history of the world.
DevelopingChris
Same problem bit me. Any suggestions for an elegant solution?
Peder Rice
Nevermind! found an answer here on StackOverflow:http://stackoverflow.com/questions/656167/hitting-the-2100-parameter-limit-sql-server-when-using-contains
Peder Rice