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 860341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:48:12+00:00 2026-05-15T08:48:12+00:00

I execute SQL scripts to change the database schema. It looks something like this:

  • 0

I execute SQL scripts to change the database schema. It looks something like this:

using (var command = connection.CreateCommand())
{
    command.CommandText = script;
    command.ExecuteNonQuery();
}

Additionally, the commands are executed within a transaction.

The scrip looks like this:

Alter Table [TableName]
ADD [NewColumn] bigint NULL

Update [TableName]
SET [NewColumn] = (SELECT somevalue FROM anothertable)

I get an error, because NewColumn does not exist. It seems to parse and validate it before it is executed.

When I execute the whole stuff in the Management Studio, I can put GO between the statements, then it works. When I put GO into the script, ADO.NET complains (Incorrect syntax near ‘GO’).

I could split the script into separate scripts and execute it in separate commands, this would be hard to handle. I could split it on every GO, parsing the script myself. I just think that there should be a better solution and that I didn’t understand something. How should scripts like this be executed?


My implementation if anyone is interested in, according to John Saunders’ answer:

List<string> lines = new List<string>();
while (!textStreamReader.EndOfStream)
{
    string line = textStreamReader.ReadLine();
    if (line.Trim().ToLower() == "go" || textStreamReader.EndOfStream)
    {
        ExecuteCommand(
            string.Join(Environment.NewLine, lines.ToArray()));

        lines.Clear();
    }
    else
    {
        lines.Add(line);
    }
}
  • 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-15T08:48:13+00:00Added an answer on May 15, 2026 at 8:48 am

    You have to run each batch separately. In particular, to run a script that may contain multiple batches (“GO” keywords), you have to split the script on the “GO” keywords.

    Not Tested:

    string script = File.ReadAllText("script.sql");
    string[] batches = script.Split(new [] {"GO"+Environment.NewLine}, StringSplitOptions.None);
    foreach (string batch in batches)
    {
        // run ExecuteNonQuery on the batch
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 492k
  • Answers 492k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are two main problems The MIME type is text/javascript,… May 16, 2026 at 10:19 am
  • Editorial Team
    Editorial Team added an answer The repo size gets larger with every commit. But git… May 16, 2026 at 10:19 am
  • Editorial Team
    Editorial Team added an answer I would recommend splitting your web application where it makes… May 16, 2026 at 10:19 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I need a database migration framework for SQL Server, capable of managing both schema
I am trying to execute a batch file from C# code using Process class.
I need to create a trigger in every database on my sql 2005 instance.
Given: MySQL database. Sometimes db schema changes and updates are rolled out (in the
As part of my (new) database version control methodology, I'm writing a change script
Using sql server 2008 I am getting and invalid precision value error in the
I just get a problem executing my sql statement, This is the Northwind db.
For my application I have to support update scenarios and the database might be
Is it possible to see the DML (SQL Statement) that is being run that
1.I have a script, that executes some update/delete operations 2.All sql operations are executed

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.