views:

83

answers:

2
SELECT MachineID, MachineName, count(ID) as Total, sum(Size) as TotalSize 
  FROM Files 
  join Machines on Files.MachineID = Machines.MachineID 
 Where Files.MachineID In(sql.Append(string.Format("@MachineId{0}", i));
 group by Files.MachineID,MachineName

now when the machinId count is less than 2100 the query is performed and if it machines go above 2100 an error is thrown 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.

how do i make increase the limit or just avoid getting this error.. and put values in gridview thanks..

+4  A: 

You don't say in your example where your "sql" variable comes from but if you manually build your 'IN' list (by building a string with comma delimited values in your IN statement), then all popular relational DBs have a limit to how many values you can specify in a static IN clause. The database your are using has a 2100 limit. I believe Oracle is 1000

mjmarsh
i am using SQL server 2005.. and i did not understand the in part..
basically, i mean when you use a statement like 'SELECT * from myTable where ID IN (1,2,3,4,5,....)'. What I am saying is that what is inside the paranthesis after the IN keyword, is limited to 2100 or fewer comma delimited values. Your code 'sql.Append(string.Format("@MachineId{0}", i)' seems to indicate you are building a list of values in a loop. My hypothesis is that when it breaks that "sql" variable has more than 2100 comma-delimited values
mjmarsh
ok.. yes that is true... i know the problem but how do i get out of it.>? like is there a way to increase the limit or put an exception(but that still wont solve it) or any other cooler way to do this... thanks for the help though.. appreciate it..
No, there is no way to increase the allowable size of the IN clause. You may have to look into passing arrays to your SQL or to a stored procedure, or using temp tables to stage the data before using it in your IN clause. See this thread for ideas: http://stackoverflow.com/questions/1869753/maximum-size-for-a-sql-server-query-in-clause-is-there-a-better-approach
mjmarsh
hmm... thanks.. ill need to understand this now... i have never used stored procedure... but its good that i do.. any pointers before i do this??
Are you sure you need to pass in all those `machineId` s manually? No way to `join` them in or select them in another way? Has a user selected 2101+ `machineId` s? Stored routine info is on http://dev.mysql.com/doc/refman/5.0/en/stored-routines.html
MvanGeest
yes it only happens when the user selects all machines.. so thats the only bug..
A: 

you could use string functions. In SQL Server your WHERE clause would be something like

...WHERE CHARINDEX(':' + <: delimited list of machine IDs> + ':', 
       ':' + CAST(Files.MachineID as VARCHAR(10)) + ':') <> 0

The : delimiters are necessary to prevent 100 from matching with 1001, 1002, 2100, etc. A sample query string would be

...WHERE CHARINDEX(':1000:1001:1002:1005:', 
       ':' + CAST(Files.MachineID as VARCHAR(10)) + ':') <> 0
potatopeelings