What is the fastest code to call multiple stored procedures?

Solution 1:

foreach (var item in itemList)
{
   myContext.ExecuteStoreCommand("EXEC MyProc {0};", item); // Insertion
}

or

Solution 2:

StringBuilder sb = new StringBuilder();
foreach (var item in itemList)
{
   sb.AppendLine(String.Format("EXEC MyProc {0};", item)); // Insertion
}
myContext.ExecuteStoreCommand(sb.ToString());
+3
source share
6 answers

The second is faster (one database call instead of several), at first it is safer, since it protects against SQL injection.

+8
source

both are , the second is under sql injection , that's for sure

after reading this and this , I agree with kekekela

+5
source

2 , myContext.ExecuteStoreCommand, context

+3
+2

, .

, .

+1

, .

SqlCommand CommandText, CommandType, CommandType.StoredProcedure, .

In addition to increasing the performance of using a special query (which will need to be re-paralleled each time), you will also address most of your current SQL injection problems at the bud.

+1
source

Source: https://habr.com/ru/post/1771735/


All Articles