Solved

Dataset - Out of memory Exception

Posted on 2011-03-17
10
901 Views
Last Modified: 2012-05-11
Hi all,

I have a database table with 60 columns.

I am bringing the data from the table into the dataview and using the dataview, i am filling a grid.
This dataset will be having around 300 rows or more.

 dataSet = New DataSet
 myDataAdapter.Fill(dataSet, "Regulars")
 dv = New DataView(dataSet.Tables("Regulars"))

This grid will refresh every 30 seconds. So, every 30 seconds, a connection to the databse is made and the above 3 steps are repeated.(Winforms Application)


Now i am getting outofmemoryexception.
Is there anything wrong with the way i am filling the grid?

Each time a dataset is created and filled, would it automatically clear or dispose the existing dataset?

Thanks in Advance

0
Comment
Question by:rowternet
  • 6
  • 3
10 Comments
 
LVL 11

Expert Comment

by:lenordiste
ID: 35160113
I am not sure if this actually is the same issue but i had a similar problem a while ago. I had to use the BindingSource property because the datagridview was not correctly releasing the dataset when I had to update it constantly.
Here is some info on "bindingsource":
http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.aspx

and here is an article from MS explaining how to fix the memory leak problem using a BindingSource:
http://connect.microsoft.com/VisualStudio/feedback/details/92260/datagrid-memory-leak-resulted-from-failed-clear-of-databind
0
 

Author Comment

by:rowternet
ID: 35160299
Hi lenordiste,

This is in production and i cannot change the code to use the binding source at this time.
There is a lot of manipulation going in there before i fill the grid.
But these are the 3 steps which i think are causingthis issue.



Whenever i use a myadapter.fill(ds), would the new data be appended  to the dataset or overwrite the existing dataset?
I assumed this would overwrite.

msdn documentation for dataadapter says this:
"You can use the Fill method multiple times on the same DataTable. If a primary key exists, incoming rows are merged with matching rows that already exist. If no primary key exists, incoming rows are appended to the DataTable."




Since i am using the ds = new dataset, what happens to the previous dataset would it be removed or no?



Thanks
0
 

Author Comment

by:rowternet
ID: 35160381
Another question:

The page that has the grid will be open atleast 12 hrs a day ata stretch.
Can i dispose the dataset after i populate teh gridview?

Would it cause any issues?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 13

Accepted Solution

by:
gamarrojgq earned 500 total points
ID: 35160424
Hi,

Depending on the scope of the dataSet variable, if the variable is declared  inside a method it should be destroyed when the method finished, but if it is declared outside a method it would persist until the CLASS that contains it is detroyed.

A couple of things you can try is to use DISPOSE method after this line

myDataAdapter.Fill(dataSet, "Regulars")

Add  this one

myDataAdapter.Dispose

This will mark the object to be destoyed, but it will be release the resource until the garbage collector happends
0
 

Author Comment

by:rowternet
ID: 35160488
hi gamarrojgg,

Depending on the scope of the dataSet variable, if the variable is declared  inside a method it should be destroyed when the method finished, but if it is declared outside a method it would persist until the CLASS that contains it is detroyed.


i think this answers my question.
This ds and dv are declared public to the class.
I may have to explicitly dispose them or use myadapter.dispose as you mentioned.

I might leave this question open for a while before i close.

Thanks

0
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35160528
ok, great, another thing would be your Connection to the Database, are you passing a Connection Object to the Dataadapter? or you are passing the STRING CONNECTION?  because the out of memory exception could happend if you have Connections leaks, so you may check that you are closing/disposing your connections
0
 

Author Comment

by:rowternet
ID: 35161099
gamarrojgg,

I should not dispose the dataset and dataview i guess that would erase the data from the gridview.
Connections are not a problem. They are being closed.

Or i have to declare the dataset and dataview locally not at form level.

Right now i am having it like this:
Dim dataSet as dataset
dim dv as dataview

public sub mymethod()
dataSet = New DataSet
 myDataAdapter.Fill(dataSet, "Regulars")
 dv = New DataView(dataSet.Tables("Regulars"))
end sub
0
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35161196
well, once your Dataview is assigned to the gridview and the DATABIND method of the gridview is called , you can Dispose you dv object.

It wont affect you grid if you dispose the Dataset and Dataview after that.
0
 

Author Comment

by:rowternet
ID: 35468198
Hi
Please Select gamarjogg comment ID:ID: 35160424 as answer.
I selected my comment as answer by mistake.

Thanks.
0
 

Author Closing Comment

by:rowternet
ID: 35468202
Thanks
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question