Click here to Skip to main content
15,896,310 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am running a program in which when I click Save button it through exception as :-

'System.OutOfMemoryException' was thrown


code where it crashes is :-


VB
Dim cmdDeleteData As New SqlCommand("delete from temp_grimage_offline", webCon)
        cmdDeleteData.ExecuteNonQuery()

        Dim bulk_BeeEnn As New SqlBulkCopy(webCon)
        bulk_BeeEnn.BulkCopyTimeout = 0
        bulk_BeeEnn.DestinationTableName = "temp_grimage_offline"

        bulk_BeeEnn.WriteToServer(ds.Tables(0))

        checkingForDataDuplicacy()
        Dim cmd_insert As New SqlCommand("insert into emp.dbo.grimage(grno,grimage,stn,scanneddate,tbb,topay,paid,[to],actualwt,chargedwt,nags,ftl,imageid,dgr,empid,grdate,nags_loose, " +
                                         "freight,hamali,l_c,st_ser,surcharge,vsc,stationary_ch,dd_chrgs,st_entry,total,upload_date) select grno,grimage,stn, " +
                                         "scanneddate,tbb,topay,paid,[to],actualwt,chargedwt,nags,ftl,imageid,dgr,empid, " +
                                         "grdate,nags_loose,freight,hamali,l_c,st_ser,surcharge,vsc,stationary_ch,dd_chrgs,st_entry,total,getdate() " +
                                         "from emp.dbo.temp_grimage_offline", webCon)
        cmd_insert.CommandTimeout = 0

        cmd_insert.ExecuteNonQuery()


        Dim cmd_update As New SqlCommand("update emp.dbo.grimage set flag = '1' where flag = '0' or flag is null", localCon)
        cmd_update.ExecuteNonQuery()
        cmd_update.CommandTimeout = 0
Posted
Updated 2-Sep-13 17:56pm
v2
Comments
Mehdi Gholam 2-Sep-13 5:49am    
Check what you are doing in the "Save" button...
Thanks7872 2-Sep-13 6:26am    
:-)
ashwani.pandita 2-Sep-13 5:51am    
initially I am saving all the data in a data set from local server and then I am transferring data from data set to the main table on the server
Yesudasan Moses 2-Sep-13 5:53am    
why u r doing like this,,, ? may be the result of never ending loop ,,,,
are you using any third party controls or extensions in it ???
ashwani.pandita 2-Sep-13 6:15am    
Sir, I ran the EXE over a system and it works properly but when I m running the EXE in another system there it throw the exception

1 solution

Without seeing your code where it crashes and the number of records where the problem occurs, it's pretty much impossible to tell you what you're doing wrong.

But, from the sounds of what you have explained, you are literally running the machine out of RAM if you're trying to load a huge table into memory all at once with a DataSet/DataTable object.
 
Share this answer
 
Comments
ashwani.pandita 2-Sep-13 23:55pm    
Sir, The machine where I am running the EXE is having 2 GB DDR3 ram and is brand new machine. Actually sir I am running this EXE on 2 different machines having same configuration. In one machine it runs smoothly but in another it through exception which I mentioned above.

the code where I am getting issue is :-


Dim cmdDeleteData As New SqlCommand("delete from temp_grimage_offline", webCon)
cmdDeleteData.ExecuteNonQuery()

Dim bulk_BeeEnn As New SqlBulkCopy(webCon)
bulk_BeeEnn.BulkCopyTimeout = 0
bulk_BeeEnn.DestinationTableName = "temp_grimage_offline"

bulk_BeeEnn.WriteToServer(ds.Tables(0))

checkingForDataDuplicacy()
Dim cmd_insert As New SqlCommand("insert into emp.dbo.grimage(grno,grimage,stn,scanneddate,tbb,topay,paid,[to],actualwt,chargedwt,nags,ftl,imageid,dgr,empid,grdate,nags_loose, " +
"freight,hamali,l_c,st_ser,surcharge,vsc,stationary_ch,dd_chrgs,st_entry,total,upload_date) select grno,grimage,stn, " +
"scanneddate,tbb,topay,paid,[to],actualwt,chargedwt,nags,ftl,imageid,dgr,empid, " +
"grdate,nags_loose,freight,hamali,l_c,st_ser,surcharge,vsc,stationary_ch,dd_chrgs,st_entry,total,getdate() " +
"from emp.dbo.temp_grimage_offline", webCon)
cmd_insert.CommandTimeout = 0

cmd_insert.ExecuteNonQuery()


Dim cmd_update As New SqlCommand("update emp.dbo.grimage set flag = '1' where flag = '0' or flag is null", localCon)
cmd_update.ExecuteNonQuery()
cmd_update.CommandTimeout = 0

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