There was an application in the project where the ID of the employee was first organized by the permission filter, then use LINQ to query the data in the appropriate table, provided that the IDs of the data from these queries must be in the ID that was filtered by the permission just now, but if there are too many IDs in the permissions, the problem is the incoming tabular data stream ( TDS) Remote Procedure Call (RPC) protocol stream is incorrect. Too many parameters are provided in this RPC request. Should be up to 2100 ". I infer that it may be the reason that the parameters in SQL Server cannot be used more than 2100. Please see the example below for the above description.
int[] inputlist = new int[2100];
for (int i = 0; i < inputlist.length; i++)
{
Inputlist[i] = i;
}
Dataclasses1datacontext dc = new Dataclasses1datacontext ();
var t= (from X in Dc.test1
Select x). Where (C=>inputlist.contains (C.testid));
dc. Log = Console.Out;
foreach (var item in t)
{
Console.WriteLine (Item.testid);
}
Running the code above will report that the incoming tabular data stream (TDS) Remote Procedure Call (RPC) protocol stream is incorrect. Too many parameters are provided in this RPC request. Should be up to 2100 "exception, if you change the inputlist array size to 5, execute SQL as follows:
SELECT [T0]. [TestID], [t0]. [Testcontent], [t0]. [P]
from [dbo]. [Test1] As [t0]
WHERE [t0].[ TestID] In (@p0, @p1, @p2, @p3, @p4)
Now the question is, if there are more than 2,100 parameters, I'm not thinking of a good way to do it with LINQ, which uses a compromise approach.
public static list<t> test<t> ()
{
Dataclasses1datacontext dc = new DataClasses 1DataContext ();
DC. Log = Console.Out;
int[] inputlist = new int[2100];
StringBuilder sqlstr = new StringBuilder ("SELECT * from");
Sqlstr. Append (typeof (T). Name);
Sqlstr. Append ("Where TestID in (");
for (int i = 0; i < inputlist.length; i++)
{
Sqlstr. Append (i);
if (i < inputlist.length-1)
{
Sqlstr. Append (",");
}
Else
{
Sqlstr. Append (")");
}
}
SqlCommand cmd = new SqlCommand (sqlstr. ToString (), (SqlConnection) DC. Connection);
DC. Connection.Open ();
SqlDataReader dr = cmd. ExecuteReader ();
List<t> t = DC. Translate<t> (DR). ToList ();
return t;
}
static void Main (string[] args)
{
List<test1> L = myclass.test<test1> () ;
foreach (var item in L)
{
Console.WriteLine (item.testid);
}
}