Hi there !
Why am I getting a 'System.OutOfMemoryException' error while "only" loading 201.293 rows ??
I'm binding to a custom datasource ( just a regular data class ) in-code, behind a search button ... please help !!!( I've turned off the viewstate for the Grid to try to load data faster ... doesn't make any difference ! )
What am I doing wrong ??
protected void _btnSearch_Click(object sender, EventArgs e) { if( (_tbBankanumer.Text == string.Empty) || (_tbHofudbok.Text == string.Empty) || (_tbReikningur.Text == string.Empty) ) { _lblBankanumerHofudbokReikningur.Text = "Please don't leave Bankanúmer, Höfuðbók or Reikningur empty - too much data to export to Excel!"; return; }
//1/1/1753 12:00:00 AM and 12/31/9999
DateTime dagsFra = new DateTime(1753,1,1); DateTime dagsTil = new DateTime(9999,12,31);
string bankanumer = _tbBankanumer.Text.Trim(); string hofudbok = _tbHofudbok.Text.Trim(); string reikningsnumer = _tbReikningur.Text.Trim(); if( _dateDagsetningFra.Value != null ) dagsFra = (DateTime)_dateDagsetningFra.Value; if( _dateDagsetningTil.Value != null ) dagsTil = (DateTime)_dateDagsetningTil.Value;
_transactions = TrackingService.GetAllAKTransactionTracksBySearchCriteria(bankanumer, hofudbok, reikningsnumer, dagsFra, dagsTil); Cache["dataFromGrid"] = _transactions; //I've tried taking this out to check if this matters ... doesn't change anything. I'm caching it so I can export the results to Excel later on !
if (_transactions.Count > 0) { _ugTransactions.DataSource = _transactions; // 201.293 rows _ugTransactions.DataBind(); //this will throw 'System.OutOfMemoryException' !!!!! }
_lblRows.Text = "Færslur úr leit: "; _lblRowCount.Text = _ugTransactions.Rows.Count.ToString();
Logger log = getLoggingDetails("RB Færslur", "Search for data"); TrackingService.LogIntoDatabase(log); _lblBankanumerHofudbokReikningur.Text = String.Empty; }
rgd,EE.
This is my Initilize-Layout function:
_ugTransactions_InitializeLayout:------------------------------------------------ protected void _ugTransactions_InitializeLayout(object sender, Infragistics.WebUI.UltraWebGrid.LayoutEventArgs e) { e.Layout.Bands[0].AllowSorting = Infragistics.WebUI.UltraWebGrid.AllowSorting.OnClient; e.Layout.Bands[0].AllowColSizing = Infragistics.WebUI.UltraWebGrid.AllowSizing.Fixed; e.Layout.Bands[0].AllowColumnMoving = Infragistics.WebUI.UltraWebGrid.AllowColumnMoving.None;
e.Layout.Bands[0].Columns.FromKey("TransTrackId").Hidden = true; e.Layout.Bands[0].Columns.FromKey("KeyrtIVoruhus").Hidden = true;
e.Layout.Bands[0].Columns.FromKey("Bankanumer").Header.Caption = "Banki"; e.Layout.Bands[0].Columns.FromKey("Bankanumer").Width = 50;
e.Layout.Bands[0].Columns.FromKey("Hofudbok").Header.Caption = "HB"; e.Layout.Bands[0].Columns.FromKey("Hofudbok").Width = 20;
e.Layout.Bands[0].Columns.FromKey("Reikningsnumer").Header.Caption = "Reikningsnúmer";
e.Layout.Bands[0].Columns.FromKey("Faerslulykill").Header.Caption = "Færsulykill"; e.Layout.Bands[0].Columns.FromKey("Faerslulykill").Width = 60;
e.Layout.Bands[0].Columns.FromKey("Upphaed").Header.Caption = "Upphæð"; e.Layout.Bands[0].Columns.FromKey("Textalykill").Header.Caption = "Textalykill"; e.Layout.Bands[0].Columns.FromKey("Tekkanumer").Header.Caption = "Tékkanúmer"; e.Layout.Bands[0].Columns.FromKey("Tilvisun").Header.Caption = "Tilvísun"; e.Layout.Bands[0].Columns.FromKey("Faersludagur").Header.Caption = "Færsludagur"; e.Layout.Bands[0].Columns.FromKey("Innlausnarbanki").Header.Caption = "Innlausnarbanki"; e.Layout.Bands[0].Columns.FromKey("Bunkanumer").Header.Caption = "Bunkanúmer"; e.Layout.Bands[0].Columns.FromKey("TegundInntaks").Header.Caption = "TegundInntaks"; e.Layout.Bands[0].Columns.FromKey("RBMatchStatus").Header.Caption = "RBMatchStatus"; e.Layout.Bands[0].Columns.FromKey("MotBankanumer").Header.Caption = "MótBankanúmer"; e.Layout.Bands[0].Columns.FromKey("MotHofudbok").Header.Caption = "MótHöfuðbók"; e.Layout.Bands[0].Columns.FromKey("MotReikningsnumer").Header.Caption = "MótReikningsnúmer"; e.Layout.Bands[0].Columns.FromKey("MotFaerslulykill").Header.Caption = "MótFærslulykill"; e.Layout.Bands[0].Columns.FromKey("MotTextalykill").Header.Caption = "MótTextalykill"; e.Layout.Bands[0].Columns.FromKey("MotTekkanumer").Header.Caption = "MótTékkanúmer"; e.Layout.Bands[0].Columns.FromKey("MotTilvisun").Header.Caption = "MótTilvísun"; e.Layout.Bands[0].Columns.FromKey("MotBunkanumer").Header.Caption = "MótBunkanúmer"; e.Layout.Bands[0].Columns.FromKey("MotKennitala").Header.Caption = "MótKennitala"; e.Layout.Bands[0].Columns.FromKey("MotNafn").Header.Caption = "MótNafn"; //Mótnafn
e.Layout.Bands[0].Columns.FromKey("AKMatchStatus").Header.Caption = "AKMatchStatus"; e.Layout.Bands[0].Columns.FromKey("AKMatchRunDate").Header.Caption = "AKMatchRunDate"; e.Layout.Bands[0].Columns.FromKey("IBASMatchStatus").Header.Caption = "IBASMatchStatus"; e.Layout.Bands[0].Columns.FromKey("IBASMatchRunDate").Header.Caption = "IBASMatchRunDate"; e.Layout.Bands[0].Columns.FromKey("Reiknnumid").Header.Caption = "Reiknnumid"; e.Layout.Bands[0].Columns.FromKey("MotReiknnumid").Header.Caption = "MótReiknnumid";
e.Layout.Bands[0].Columns.FromKey("Bankanumer").Move(1); e.Layout.Bands[0].Columns.FromKey("Hofudbok").Move(2); e.Layout.Bands[0].Columns.FromKey("Reikningsnumer").Move(3); e.Layout.Bands[0].Columns.FromKey("Faerslulykill").Move(4); e.Layout.Bands[0].Columns.FromKey("Upphaed").Move(5); e.Layout.Bands[0].Columns.FromKey("MotBankanumer").Move(6); e.Layout.Bands[0].Columns.FromKey("MotHofudbok").Move(7); e.Layout.Bands[0].Columns.FromKey("MotReikningsnumer").Move(8); e.Layout.Bands[0].Columns.FromKey("MotKennitala").Move(9); e.Layout.Bands[0].Columns.FromKey("MotNafn").Move(10); e.Layout.Bands[0].Columns.FromKey("Textalykill").Move(11); e.Layout.Bands[0].Columns.FromKey("Tekkanumer").Move(12); e.Layout.Bands[0].Columns.FromKey("Tilvisun").Move(13); e.Layout.Bands[0].Columns.FromKey("Faersludagur").Move(14); e.Layout.Bands[0].Columns.FromKey("Innlausnarbanki").Move(15); e.Layout.Bands[0].Columns.FromKey("Bunkanumer").Move(16); e.Layout.Bands[0].Columns.FromKey("TegundInntaks").Move(17); e.Layout.Bands[0].Columns.FromKey("RBMatchStatus").Move(18); e.Layout.Bands[0].Columns.FromKey("MotFaerslulykill").Move(19); e.Layout.Bands[0].Columns.FromKey("MotTextalykill").Move(20); e.Layout.Bands[0].Columns.FromKey("MotTekkanumer").Move(21); e.Layout.Bands[0].Columns.FromKey("MotTilvisun").Move(22); e.Layout.Bands[0].Columns.FromKey("MotBunkanumer").Move(23); }
and this is the data class I'm binding to if it matters ... public class AKTransactionTrack { private int _transTrackId; private string _bankanumer = String.Empty; private string _hofudbok = String.Empty; private string _reikningsnumer = String.Empty; private string _faerslulykill = String.Empty; private decimal _upphaed; private string _textalykill = String.Empty; private string _tekkanumer = String.Empty; private string _tilvisun = String.Empty; private DateTime _faersludagur; private string _innlausnarbanki = String.Empty; private string _bunkanumer = String.Empty; private string _tegundInntaks = String.Empty; private string _rBMatchStatus = String.Empty; private string _motBankanumer = String.Empty; private string _motHofudbok = String.Empty; private string _motReikningsnumer = String.Empty; private string _motFaerslulykill = String.Empty; private string _motTextalykill = String.Empty; private string _motTekkanumer = String.Empty; private string _motTilvisun = String.Empty; private string _motBunkanumer = String.Empty; private string _motKennitala = String.Empty; private string _motNafn = String.Empty;
private DateTime _keyrtIVoruhus; private string _aKMatchStatus = String.Empty; private DateTime _aKMatchRunDate; private string _iBASMatchStatus = String.Empty; private DateTime _iBASMatchRunDate; private int _reiknnumid; private int _motReiknnumid;}
I'm still waiting for a reply !!! anybody ????
What am I doing wrong, to get an OutOfMemoryException with these 201.293 rows ??Do I need to enable paging or something ??? How would I do that with the Grid ....
Please help!
It's very likely that the error is exactly what it states - your web server is running out of memory. Depending on how much data is included in your data objects, and how much memory you have available, this may well be expected . Databinding is the most memory-intenstive task that WebGrid performs, if I recall correcctly.
The first solution I can suggest to minimize the memory used with databinding is to enable the grid's AJAX functionality. This will reduce the number of grid rows created significantly, and is likely to speed up data binding.
If enabling the grid's AJAX isn't enough on its own, then also use the grid's partial databinding functionality (also called 'data windowing"). By using this, you can retrieve the data objects specific to what the grid needs at that moment, which will further reduce the grid's memory usage for data binding. The following article from our online help documentation of NetAdvantage for .NET 2009 Volume 1 provides information on partial databinding wtih WebGrid:Partial Data Binding
For putting data into the grid using InitializeDataSource:
You need to make sure that your grid's DataSoruce property (and DataMember, if you need it) is set in this method, and that the data object has data available. Remember that the grid will call DataBind() implicitly once InitializeDataSource finishes, and this is run very early in the page lifecycle.
My best suggestion is to not bind the gird in a button click, since this adds an extra layer of complexity. If you absolutely need to bind in a button click, you'll need to save information on the server (whether in Session state, Cache, or something else) so that the grid can tell during later callbacks and postbacks that the button was cilcked and that it's OK to bind. Typically, this is more trouble to implement than it's worth.
-----
For your paging issue:
If you haven't configured InitializeDataSource as above, paging will not work. I recommend that you get the grid working first without paging (with less data to avoid the OutOfMemoryException), then add paging afterward.
I don't understand what you mean by "push the [2]" in this context.
---
For databinding to a hierarchical structure:
If you have the grid's AutoGenerateColumns property set to true, then it'll create child bands for you as well. A child band must be exposed by an IEnumerable property on the data object in your parent list.
Remember that WebGrid can display one child collection per parent , and it expects homogenous data (each set of child rows at a given level to have the same structure as the others at the same level). if you want multiple inheritance or heterogenous data, you'll want to look at WebHierarchicalDataGrid.
If you need more specific assistance in implementing specific things we've discussed here, I strongly recommend that you submit a support request for each issue for which you need help. A Developer Supoprt Engineer will work with you on each case to find resolutions, in a more detailed and personal manner than we can provide through these peer-to-peer forums.
Do I need to enable something special in the Grid for it to be able to databind to Hierarchial structure like this ?It will not show the collection under neath my base type ... will I need to specify it specificly ??
... any why is paging not working for me ?It does page the grid but when I push the [2] ( which should have 82 records )because [1] has 100 ... the total datasource is 182 records
protected
e)
{
System.Security.Principal.
.GetCurrent();
(identity);
))
//creates an entry for LogViewer
Response.Redirect(
);
}
//_ugTransactions.EnableViewState = false;
(!Page.IsPostBack)
_ugTransactions.DisplayLayout.LoadOnDemand = Infragistics.WebUI.UltraWebGrid.
.Automatic;
//_ugTransactions.Browser = Infragistics.WebUI.UltraWebGrid.BrowserLevel.Auto;
_ugTransactions.DisplayLayout.Pager.AllowPaging =
;
_ugTransactions.DisplayLayout.Pager.PageSize = 100;
/*_tbBankanumer.Text = "0329";
_tbHofudbok.Text = "26";
_tbReikningur.Text = "456998";*/
I'm trying something like this ... but the datasource is always empty becuase the Initilize_DataSource fires BEFORE the _buttonSearch_Click:
How would you do this .... ?
.Empty) )
_lblBankanumerHofudbokReikningur.Text =
(1753,1,1);
(9999,12,31);
bankanumer = _tbBankanumer.Text.Trim();
hofudbok = _tbHofudbok.Text.Trim();
reikningsnumer = _tbReikningur.Text.Trim();
)
dagsFra = (
)_dateDagsetningFra.Value;
dagsTil = (
)_dateDagsetningTil.Value;
_transactions =
.GetAllAKTransactionTracksBySearchCriteria(bankanumer, hofudbok, reikningsnumer, dagsFra, dagsTil);
_lblRows.Text =
_lblRowCount.Text = _ugTransactions.Rows.Count.ToString();
.LogIntoDatabase(log);
.Empty;
) // this is always null !!!
Cache[
] = _transactions;
(_transactions.Count > 0)
_ugTransactions.DataSource = _transactions;
_ugTransactions.DataBind();
//this will throw 'System.OutOfMemoryException' !!!!!
I have taken out the ViewState = false part ...
But when I push page-2 on the Grid ( with 100 rows in each ) the Grid's empty
I'm moving the code as we speak to the Initilize_datesource, would you take the whole code from the _btnSearch_Click or how would you implement this ... when is the Initilize_Datasource called ? I need to set the search-conditions ( e.g. behind the _btnSearch_Click event ) before any data is taken from the database .... ?
rgd,EE