Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Friends,

am inserting large xmlfile into mysqldatabase.But got error System.out of memory Exception.how to solve.plz help me.this is my code .thanks
C#
using ( var stringWriter = new StringWriter ( ) )
    {
    using ( var xmlTextWriter = XmlWriter.Create ( stringWriter ) )
        {
        XmlDoc2.WriteTo ( xmlTextWriter );
        xmlTextWriter.Flush ( );
        stringWriter.GetStringBuilder ( ).ToString ( );
        string xmlstr = stringWriter.GetStringBuilder ( ).ToString ( );
        DateTime today = DateTime.Now;
        string strqry =
            "insert into xmlfile ( XMLFile, DateTime) " +
            "values ( @XMLFile, @DateTime )";
        MySqlCommand cmd = new MySqlCommand ( strqry, connection, trns );
        cmd.Parameters.AddWithValue ( "@XMLFile", xmlstr );
        cmd.Parameters.AddWithValue ( "@DateTime", today );
        cmd.ExecuteNonQuery ( );
        }
    }
Posted
Updated 9-May-15 5:35am
v2
Comments
Richard MacCutchan 9-May-15 4:53am    
SystemOutOfMemory suggests that there is some fundamental problem with your program consuming resources and not releasing them. You need to look more closely at your whole application to see what it is doing.
José Amílcar Casimiro 9-May-15 6:38am    
Post your exception output, i want to see the stack trace.
gggustafson 9-May-15 11:36am    
why are there two stringWriter.GetStringBuilder ( ).ToString ( ); ? Have you confirmed that XmlDoc2 is a valid XmlDocument?

1 solution

The problem that you are facing "OutOfMemoryException" means that there is not enough memory (RAM space) left, so you might consider releasing some space.

A few options as a solution to this problem include that you try to restart your machine. This would refresh your machine's memory and would allow you to run processes again. This would be helpful, if your memory size is low (less than 1 GB). Your processes might go through a hiccup through processing and you get "Not responding" too much. Then this option would be good.

Otherwise, if your RAM size is more than 1 GB. Then the solution would be to make sure you are not having a lot of start up applications that run underground and cause your system to have multiple hiccups. These start up applications and processes run through out the life cycle of your system (notably the Windows services cause the same). The solution would never be to stop developing the WPF application, go on. Do it! The solution is to cut short the underground applications, processes and services. Your development environment must have enough resources which you want to use to complete a process.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900