Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6153117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:02:22+00:00 2026-05-23T20:02:22+00:00

I am asking a question that is related to Execute multiple SQL commands in

  • 0

I am asking a question that is related to Execute multiple SQL commands in one round trip but not exactly the same because I am having this problem on a much bigger scale:

I have an input file with many different SQL commands (ExecuteNonQuery) that I have to process with a .net application.
Example:

INSERT INTO USERS (name, password) VALUES (@name, @pw); @name="abc"; @pw="def";
DELETE FROM USERS WHERE name=@name; @name="ghi";
INSERT INTO USERS (name, password) VALUES (@name, @pw); @name="mno"; @pw="pqr";

All of the commands have parameters so I would like the parameter mechanism that .net provides. But my application has to read these statements and execute them within an acceptable time span. There might be multiple thousand statements in one single file.

My first thought was to use SQLCommand with parameters since that would really be the way to do it properly (parameters are escaped by .net) but I can’t afford to wait 50msec for each command to complete (network communication with DB server, …). I need a way to chain the commands.

My second thought was to escape and insert the parameters myself so I could combine multiple commands in one SQLCommand:

INSERT INTO USERS (name, password) VALUES ('abc', 'def'); DELETE FROM USERS WHERE name=@name; @name='ghi'; INSERT INTO USERS (name, password) VALUES ('mno', 'pqr');

However I do feel uneasy with this solution because I don’t like to escape the input myself if there are predefined functions to do it.

What would you do? Thanks for your answers, Chris

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:02:22+00:00Added an answer on May 23, 2026 at 8:02 pm

    Assuming everything in the input is valid, what I would do is this:

    • Parse out the parameter names and values
    • Rewrite the parameter names so they are unique across all queries (i.e., so you would be able to execute two queries with a @name parameter in the same batch)
    • Group together a bunch of queries into a single batch and run the batches inside a transaction

    The reason why you (likely) won’t be able to run this all in a single batch is because there is a parameter limit of 2100 in a single batch (at least there was when I did this same thing with SQL Server); depending on the performance you get, you’ll want to tweak the batch separation limit. 250-500 worked best for my workload; YMMV.

    One thing I would not do is multi-thread this. If the input is arbitrary, the program has no idea if the order of the operations is important; therefore, you can’t start splitting up the queries to run simultaneously.

    Honestly, as long as you can get the queries to the server somehow, you’re probably in good shape. With only “multiple thousands” of statements, the whole process won’t take very long. (The application I wrote had to do this with several million statements.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was asking a related question but messed the title up and no-one would
I apologize for asking such a generalized question, but it's something that can prove
Sorry for asking this question, but I searched all Java-related questions, but I got
I went through the suggested related topics before asking this question but none of
Not even sure if I'm asking the right question, but here it goes. Basically
Before answering this question, understand that I am not asking how to create my
This is a question related to another one I asked that was specific to
Apologies for asking what is likely be a configuration related question, but I've been
I'm asking and answering my own question , but i'm not assuming i have
I'm very new to using Linq-to-SQL, that's why I'm asking this question. I've searched

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.