views:

158

answers:

1

Hello; these below codes give whole data of my Rehber datas. But if i want to show web page via Gridview send me out of memory exception error.

GenoTip.BAL:



    public static List<Rehber> GetAllDataOfRehber()
        {
            using (GenoTipSatisEntities genSatisCtx = new GenoTipSatisEntities())
            {
                ObjectQuery<Rehber> rehber = genSatisCtx.Rehber;
                return rehber.ToList();
            }
        }

if i bind data directly dummy gridview like that no problem occures every thing is great!!!

 <asp:GridView ID="gwRehber" runat="server">

       </asp:GridView>

if above codes send data to Satis.aspx page:

using GenoTip.BAL;


namespace GenoTip.Web.ContentPages.Satis
{
    public partial class Satis : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                gwRehber.DataSource = SatisServices.GetAllDataOfRehber();
                gwRehber.DataBind();
                //gwRehber.Columns[0].Visible = false;
            }
        }
    }
}

but i rearranged my gridview send me out of memory exception!!!! i need this arrangenment to show deta!!!

 <asp:GridView ID="gwRehber" runat="server">
       <Columns>
      <%-- <asp:TemplateField>
       <ItemTemplate>
        <asp:Button runat="server" ID="btnID" CommandName="select"  CommandArgument='<%# Eval("ID") %>'  Text="Seç" />
       </ItemTemplate>

       </asp:TemplateField>--%>
       <asp:BoundField DataField="Ad" HeaderText="Ad" />
       <asp:BoundField DataField="BireyID" HeaderText="BireyID" Visible="false" />
       <asp:BoundField DataField="Degistiren" HeaderText="Değiştiren" />
        <asp:BoundField DataField="EklemeTarihi" HeaderText="EklemeTarihi" />
       <asp:BoundField DataField="DegistirmeTarihi" HeaderText="Değiştirme Tarihi" Visible="false" />
       <asp:BoundField DataField="Ekleyen" HeaderText="Ekleyen" />
        <asp:BoundField DataField="ID" HeaderText="ID" Visible="false" />
       <asp:BoundField DataField="Imza" HeaderText="Imza" />
        <asp:BoundField DataField="KurumID" HeaderText="KurumID" Visible="false" />
       </Columns>
       </asp:GridView>

Error Detail :

[OutOfMemoryException: 'System.OutOfMemoryException' türünde özel durum oluşturuldu.] System.String.GetStringForStringBuilder(String value, Int32 startIndex, Int32 length, Int32 capacity) +29 System.Convert.ToBase64String(Byte[] inArray, Int32 offset, Int32 length, Base64FormattingOptions options) +146 System.Web.UI.ObjectStateFormatter.Serialize(Object stateGraph) +183 System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Serialize(Object state) +4 System.Web.UI.Util.SerializeWithAssert(IStateFormatter formatter, Object stateGraph) +37 System.Web.UI.HiddenFieldPageStatePersister.Save() +79 System.Web.UI.Page.SavePageStateToPersistenceMedium(Object state) +105 System.Web.UI.Page.SaveAllState() +236 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1099

A: 

So it looks like to problem is that you are putting too much into state; most likely this means one (or both) of:

  • you are reading far, far too many rows
  • the serializer is walking the (perhaps lazy-loaded?) properties, causing more data than you expect to be loaded / serialized

To combat this, I would suggest projecting instead to a simple DTO model before doing anything that could put the data into state (so you know exactly what data you are serializing), and to look closely about how many rows you are handling (using Take and Where appropriately).

Marc Gravell