Quantcast
Channel: User Chris W. Rea - Stack Overflow
Viewing all articles
Browse latest Browse all 42

Answer by Chris W. Rea for Mass sending data to stored procedure

$
0
0

You can pass a text batch of statements to the database. It can be quite efficient.

Instead of creating a SqlCommand of CommandType.StoredProcedure and taking a single stored procedure name and set of parameters – which, as you suspect, will perform poorly if you round-trip to the database for each record – you can instead create a SqlCommand of CommandType.Text, and then construct a text batch containing multiple SQL statements (which would be invocations of your stored procedure.) Separate each statement with a semi-colon.

Another advantage of a text batch is that your stored procedure can be kept simple and just process a single record at a time.

But, be careful: You need to ensure your parameters are properly quoted / escaped, because creating a plain text batch instead of using CommandType.StoredProcedure (with parameters) opens you up to SQL-injection type vulnerabilities.


Viewing all articles
Browse latest Browse all 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>