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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:27:32+00:00 2026-05-14T16:27:32+00:00

StringBuilder query = new StringBuilder(); query.Append(CREATE TABLE #Codes (Code nvarchar(100) collate database_default ) );

  • 0
StringBuilder query = new StringBuilder();
                    query.Append("CREATE TABLE #Codes (Code nvarchar(100) collate database_default ) ");
                    query.Append("Insert into #Codes (Code) ");
                    int lengthOfCodesArray = targetCodes.Length;
                    for (int index = 0; index < lengthOfCodesArray; index++)
                    {
                        string targetCode = targetCodes[index];
                        query.Append("Select N'" + targetCode + "' ");
                        if (index != lengthOfCodesArray - 1)
                        {
                            query.Append("Union All ");
                        }
                    }
  query.Append("drop table #Codes ");

on: cmd.ExecuteReader() I get

There is insufficient system memory to run this query when creating temporary table

But weird thing is that, when I have 25k codes is ok, when 5k I get this error. 

Initial size is 262 MB.

Lengt of each code is average 15.

  • 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-14T16:27:33+00:00Added an answer on May 14, 2026 at 4:27 pm

    This produces one giant statement, and of course it fails eventually.

    You should do your INSERT one at a time (no UNION ALL), at least until it’s time to optimize.

    I have a feeling that your ultimate answer is going to involve BULK INSERT, but I don’t know enough about your application to be sure.

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

Sidebar

Related Questions

If I do: StringBuilder sb = new StringBuilder(); sb.append(somestring + hello + more strings
Have following String built SQL query: StringBuilder querySelect = new StringBuilder(select * from messages
I want Insert Data Table in DataBase public void InsertNote(DataTable dataTable) { var query
Can extensive StringBuilder.Append() operations be optimized by using char[] allocated on thread's stack to
I have the following: StringBuilder errors = new StringBuilder(); if(IsNullOrEmpty(value)) { errors.AppendLine(Enter value); }
Say I have a StringBuilder object var sb = new StringBuilder(); And an arbritrary
I'm trying to use stringbuilder to create a body of string to be used
Is there a way to create a StringBuilder from a byte[] ? I want
I just found some sql query build like this in my project: return (new
I would like to query a table based on a list of KeyValuePair .

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.