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

  • SEARCH
  • Home
  • 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 7636999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:49:49+00:00 2026-05-31T07:49:49+00:00

I know there is a class system.data.sqlclient.sqlcommand that can execute a batch at a

  • 0

I know there is a class system.data.sqlclient.sqlcommand that can execute a batch at a time. Since I have a lot if SQL Server scripts (in which there is some GO key words in it), I need to find a way that can throw this script to SQL Server for executing. How to do this ? Thanks.


Edit:

Hi Enrico, thanks for the information you provided. The executenonquery method will return a int[] type. How can I get all the text result? For example, I have this SQL script called sql.sql.

PRINT 'blah blah blah';
GO
SELECT @@SERVERNAME AS instance;

When I use sqlcmd to execute it, I get the following result.

C:\TEMP>sqlcmd -S (local)\instance1 -U a -P a -i sql.sql
blah blah blah
instance

-------------------------------------------------------------------
THESIMPSONS\INSTANCE1


(1 rows affected)

C:\TEMP>

How can I get the similar result using SMO or ADO.NET classes? Thanks.

  • 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-31T07:49:50+00:00Added an answer on May 31, 2026 at 7:49 am

    The ServerConnection.ExecuteNonQuery method part of the SQL Server Management Objects (SMO) API will correctly execute T-SQL scripts that contain multiple batches separated by the GO keyword.

    As a side note, you can even decide to use your own batch separator by setting the ServerConnection.BatchSeparator property, which by default is "GO".

    If your script returns multiple result sets that you wish to get back in your application, you can use either the ServerConnection.ExecuteReader or the ServerConnection.ExecuteWithResults method. However, keep in mind that those methods do not support T-SQL scripts with multiple batches. At this point you have a couple of options:

    • Split the script on the "GO" separator into multiple strings, each containing a single batch, and execute them through one of the methods mentioned above.
    • Invoke SQLCMD from your code by spawning a new process and passing the script to execute as a parameter.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to know if there's any way to force the System.Net.Dns class to
I'd like to know if there is any .Net class that allows me to
I know there have been a lot of questions about Entity Framework doing cross
I Know there's a Vector class in java, but it seems to be just
I'd like to know if there is any class in Java able to check,
First, I know there are methods off of the generic List<> class already in
As we know to generate a class file there should be atleast one class
Is there a way for a class called inside another to know the name
Does anyone know what advantages (memory/speed) there are by using a class generated by
Consider this class hierarchy: Book extends Goods Book implements Taxable As we know, there

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.