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

Let's suppose that we have multi-site CMS and every website in this CMS having
I have multi databases with same structure its name like that Client1234 the different
How can I have multi-column text flow in div for XHTML please? (if possible)
I have a multi-threaded application in a POSIX/Linux environment - I have no control
I have a multi-component UIPickerView in my application. Two components are plain and completely
I have a multi-threaded application build in C# using VS2010 Professional. It's quite a
I have a multi module Spring project that I set up using Maven: my-root
I have a multi-layered animation, comprised of motion tweens at the moment. I would
I have a large multi-directional form that validates almost all fields with Jquery Validator,
I have implemented a multi-threaded program which involves spawning a thread for each user,and

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.