DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2005
    Posts
    105

    Out of memory error

    Hi all:

    I creating a data range control to be used on several pages in my site. It gives me an out of memory error when entering the do/while loop but I can't figure out why. Does anything jump out at you guys?

    Code:
    private void Page_Load(object sender, System.EventArgs e)
    {            
                SqlConnection cnn = new SqlConnection(ConfigurationManager.AppSettings["CnnString"]);
                SqlCommand myCommand;
                SqlDataReader myReader;
                ArrayList dateTimeList;
                DateTime dtBegin;
                DateTime dtEnd;
                
                if (!IsPostBack)
                {
                    dtBegin = Convert.ToDateTime(string.Format("{0:MM/dd/yyyy}", "10/1/2005"));
                    cnn.Open();
                    myCommand = new SqlCommand();
                    myCommand.Connection = cnn;
                    myCommand.CommandType = CommandType.StoredProcedure;
                    myCommand.CommandText = "usp_GetDate";
    
                    dateTimeList = new ArrayList();
    
                    myReader = myCommand.ExecuteReader();
    
                    if (myReader.HasRows)
                    {
                        myReader.Read();
                        dtEnd = Convert.ToDateTime(myReader[0]);
    
                    }
                   
                        do
                        {
                            dateTimeList.Add(string.Format("{0:MM/dd/yyyy}", dtBegin)); 
                            dtBegin = DateAdd(DateInterval.Day, 1, dtBegin); 
                        }
                        while (!(dtEnd < dtBegin));
                    
                      dateTimeList.Reverse(); 
                
                      ddlBeginDate.DataSource = dateTimeList; 
                      ddlBeginDate.DataBind(); 
                
                      ddlEndDate.DataSource = dateTimeList; 
                      ddlEndDate.DataBind();
                  }
                 
                    myReader.Close();
                    myCommand.Dispose();
                    cnn.Close();
                    cnn.Dispose();
             }
    }

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649
    Are the end and begin dates valid?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Mar 2005
    Posts
    105
    Quote Originally Posted by Hack
    Are the end and begin dates valid?
    To my knowledge. I used a Response.Write to print both dates out and they look fine.

    begin = 10/1/2005 12:00:00 AM
    end = 2/12/2008 12:00:00 AM

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649
    Does it immediately get the out of memory error or does it churn for a while first?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  5. #5
    Join Date
    Mar 2005
    Posts
    105
    It churns for a long while before the error appears. For a while, it locked my machine up. So, I added a try/catch and now it errors out immediately. I'm about to step thru the code and see what I can gather.

  6. #6
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649
    Quote Originally Posted by nickiii
    I'm about to step thru the code and see what I can gather.
    That was going to be my next question (have you?)

    You should be able to pinpoint where it is going off into the ether.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  7. #7
    Join Date
    Mar 2005
    Posts
    105
    Problem is it's not incrementing the days as it goes through the loop. Guess I need to use something other than "AddDays()".

  8. #8
    Join Date
    Mar 2005
    Posts
    105
    Oh silly me. It should be

    Code:
     dtBegin = dtBegin.AddDays(1);
    Instead of
    Code:
     dtBegin.AddDays(1);
    Problem resolved.

    Thanks Hack!

  9. #9
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649
    My pleasure.

    Anytime I can do virtually nothing for you, just let me know.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. Replies: 0
    Last Post: 11-24-2007, 06:34 AM
  2. j2me out of memory error
    By jonneymendoza in forum Java
    Replies: 0
    Last Post: 04-24-2007, 04:28 AM
  3. Re: Error handling in components called from ASP
    By James Barbetti in forum ASP.NET
    Replies: 2
    Last Post: 11-06-2001, 01:13 PM
  4. Replies: 0
    Last Post: 09-06-2001, 09:37 AM
  5. Sample Sites.
    By Murray Foxcroft in forum Web
    Replies: 5
    Last Post: 11-02-2000, 02:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links