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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:31:09+00:00 2026-05-15T09:31:09+00:00

I am getting a system.outofmemory exception in my code: While r1.Read() menu1id = r1(id)

  • 0

I am getting a system.outofmemory exception in my code:

While r1.Read()
                    menu1id = r1("id")
                    db.AddInParameter(command2, "@menu1id", DbType.Int32, menu1id)
                    r2 = db.ExecuteReader(command2)
                    command2.Parameters.Clear()
                    menu1heading = r1("Heading")
                    If r1("url") IsNot Nothing And r1("moduleid") = 0 Then
                        url = r1("url").ToString

                        If InStr(url, "file:///") > 0 Then
                            Dim builder As New StringBuilder
                            builder.Append("<a href=")
                            builder.Append(r1("url"))
                            builder.Append(" target=")
                            builder.Append(r1("urltarget"))
                            builder.Append(">")
                            builder.Append(menu1heading)
                            builder.Append("</a>")
                            level1.Add(builder.ToString)
                        Else
                            Dim builder As New StringBuilder
                            builder.Append("<a href=http://")
                            builder.Append(r1("url"))
                            builder.Append(" target=")
                            builder.Append(r1("urltarget"))
                            builder.Append(">")
                            builder.Append(menu1heading)
                            builder.Append("</a>")
                            level1.Add(builder.ToString)
                        End If
                    Else
                        Dim builder As New StringBuilder
                        builder.Append("<a href=~/Default.aspx?id=")
                        builder.Append(r1("id"))
                        builder.Append(">")
                        builder.Append(menu1heading)
                        builder.Append("</a>")
                        level1.Add(builder.ToString)
                    End If


                    While r2.Read
                        menu2id = r2("id")
                        db.AddInParameter(command3, "@menu2id", DbType.Int32, menu2id)
                        r3 = db.ExecuteReader(command3)
                        command3.Parameters.Clear()
                        menu2heading = r2("Heading")

                        If r2("url") IsNot Nothing And r2("moduleid") = 0 Then
                            Dim builder As New StringBuilder
                            builder.Append("<a href=http://")
                            builder.Append(r2("url"))
                            builder.Append(" target=")
                            builder.Append(r2("urltarget"))
                            builder.Append(menu2heading)
                            builder.Append("</a>")
                            level2.Add(builder.ToString)
                        Else
                            Dim builder As New StringBuilder
                            builder.Append("<a href=~/Default.aspx?id=")
                            builder.Append(r2("id"))
                            builder.Append(">")
                            builder.Append(menu2heading)
                            builder.Append("</a>")
                            level2.Add(builder.ToString)
                        End If


                        While r3.Read
                            menu3heading = r3("Heading")
                            menu3id = r3("id")
                            If r3("url") IsNot Nothing And r3("moduleid") = 0 Then
                                Dim builder As New StringBuilder
                                builder.Append("<a href=http://")
                                builder.Append(r3("url"))
                                builder.Append(" target=")
                                builder.Append(r3("urltarget"))
                                builder.Append(">")
                                builder.Append(menu3heading)
                                builder.Append("</a>")
                                level3.Add(builder.ToString)
                            Else
                                Dim builder As New StringBuilder
                                builder.Append("<a href=~/Default.aspx?id=")
                                builder.Append(r3("id"))
                                builder.Append(">")
                                builder.Append(menu3heading)
                                builder.Append("</a>")
                                level3.Add(builder.ToString)
                            End If

                        End While

                        r3.Close()
                    End While

                    r2.Close()
                End While

                r1.Close()
            End While
            r0.Close()

Please can you tell me how I go about diagnosing and fixing this exception? thanks a lot.

  • 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-15T09:31:10+00:00Added an answer on May 15, 2026 at 9:31 am

    You would be a lot better off changing your logic to a single sql query that returns all of your menu items in one go and then iterating this dataset to build your menu.

    You could just try

    SELECT id, DepartmentID, GroupingID, Heading, OrderID, 
    Publish, moduleid, url, urltarget
    FROM Grouping 
    WHERE (DepartmentID = 0 AND Publish <> 0)
    ORDER BY OrderID
    

    This returns all of the data that the above queries return, including the GroupingID which determines the tree structure. You should be able to load up the results into a collection of objects and then query them using LINQ to build your menu.

    Copy your data into the following class annd then use LINQ on a list of them:

    public class DataClass
    {
    public string Id { get; set; }
    public string DepartmentID { get; set; }
    public string GroupingID { get; set; }
    public string Heading { get; set; }
    public string OrderID { get; set; }
    public string Publish { get; set; }
    public string Moduleid { get; set; }
    public string Url { get; set; }
    public string Urltarget { get; set; }
    
    public List<DataClass> Children { get; set; }
    
    public DataClass(string id, string departmentID, string groupingID, string heading, string orderID, string publish, string moduleid, string url, string urltarget)
    {
        Id = id;
        DepartmentID = departmentID; 
        GroupingID = groupingID;
        Heading = heading;
        OrderID = orderID; 
        Publish = publish;
        Moduleid = moduleid;
        Url = url;
        Urltarget = urltarget;
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use: function getRadioValue(name) { var group = document.getElementsByName(name); for (var… May 16, 2026 at 11:41 pm
  • Editorial Team
    Editorial Team added an answer in case you are still interested, I recently developed a… May 16, 2026 at 11:41 pm
  • Editorial Team
    Editorial Team added an answer I realized I was using a very very large version… May 16, 2026 at 11:41 pm

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 keep getting a 'System.OutOfMemoryException' thrown at the code below. I can't figure out
I am running a fairly large search, and am getting a System.OutOfMemoryException. The problem
After Getting a System.Reflection.PropertInfo array for a class- Does anyone know how or if
Getting this error: System.Data.SqlClient.SqlException : The conversion of a datetime2 data type to a
I am having problems getting Microsoft Charting: System.Web.DataVisualization.dll To work in the Medium Trust
I have an XmlReader that is trying to read text into a list of
Let's say I have the following code... StringBuilder sb = new StringBuilder(); for (int
code snippet: //byte[] myByteArray = byte array from database (database BLOB) myByteArray = (byte[])
I am using Visual C# Express 2008 and I have an application that starts
I have a dynamic query that returns around 590,000 records. It runs successfully the

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.