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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:46:37+00:00 2026-05-18T00:46:37+00:00

I have a multi-megabyte .sql file, there are GO statements on newlines every 10k

  • 0

I have a multi-megabyte .sql file, there are GO statements on newlines every 10k or so. I am trying to come up with a way to read the file, line-by-line, until I hit a new line that only has “go” and a Newline character, then return what was read to the caller, and then read the next bunch of text until I hit GO again.

Peek only lets me read one character, what’s a smart way to make this work in C# on Framework 4.0?

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-18T00:46:38+00:00Added an answer on May 18, 2026 at 12:46 am

    This should do exactly what you were saying.
    Call this function with a string of the filename of the SQL file, and it will return an IEnumerable<string> (a bunch of strings) that each hold a SQL batch (each up until a GO statement) which you can then loop through with foreach or anything else.

    public static IEnumerable<string> GetSqlBatches(string filename)
    {
        using(StreamReader sr = new StreamReader(filename))
        {
            StringBuilder ReadSoFar = new StringBuilder();
    
            while (!sr.EndOfStream)
            {
                string line = sr.ReadLine();
                ReadSoFar.AppendLine(line);
                if (line.Trim() == "GO")
                {
                    yield return ReadSoFar.ToString();
                    ReadSoFar = new StringBuilder();
                }
            }
            sr.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to have multi-line plain-text, constant literals in C++, à la
We have multi GB files coming every day to be loaded to SQL Server
I'm using 'rails3-jquery-autocomplete' gem, but it doesn't have multi column search, but there is
I have a multi-line string that I want to do an operation on each
I have a multi-user ASP.NET app running against SQL Server and want to have
What is the best way to design the Domain objects which can have multi-lingual
Let's suppose that we have multi-site CMS and every website in this CMS having
Wondering if there is a way to have multicolor text for ASP.NET Button Text.
I have multi databases in SQL Server. And database design such as Database1 Database1_Tmp,
I'm integrate this plugin and his file input doesnt have multi file selection. So

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.