Trouble binding WebGrid to ObjectDataSource using DataSet - OutOfMemoryException

5 replies. Last post: February 9, 2012 11:23 PM by Ahmed Dajani
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback
Ahmed DajaniMember

Hi,

I've been stuck on the following problem for a week and it's driving me nuts! Please help.

The code below works fine on my development machine (VS 2010 .NET 4.0) but continues to fail on the server (IIS 7 .NET 4.0 RAM: 4GB). Basically I'm trying to bind my grid with an ObjectDataSource using a DataSet, or even a DataTable. Simple task!

aspx:


<%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="Default.aspx.vb" Inherits="TestWebGrid._Default" %>
<%@ MasterType VirtualPath="~/Site.Master" %>
<%@ Register Assembly="ISNet.WebUI.WebGrid" Namespace="ISNet.WebUI.WebGrid" TagPrefix="ISWebGrid" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<ISWebGrid:WebGrid ID="myGrid" runat="server" Height="300px" Width="100%" UseDefaultStyle="true"         DataSourceID="odsMyList">
        <RootTable GridLineStyle="NotSet" DataKeyField="some_id">
            <Columns>
                <ISWebGrid:WebGridColumn Name="some_id" DataMember="some_id"/>
            </Columns>
        </RootTable>
        <LayoutSettings GridLines="Default" AllowDelete="No" AllowEdit="No" AllowAddNew="No" >
        </LayoutSettings>
    </ISWebGrid:WebGrid>
    <asp:ObjectDataSource ID="odsMyList" runat="server" 
                          TypeName="WebGridBLL.WebGridManager" 
                          SelectMethod="GetData">
        <SelectParameters>
            <asp:Parameter DefaultValue="0" Name="myParam" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
</asp:Content>


There's nothing to do in the code behind of the ASPX.

My BLL is in the same solution and the references are added fine.

BLL:

Imports System.Data
Imports System.Data.SqlClient
Public Class WebGridManager
' note blocked out connection string
    Private ReadOnly _connectionString As String = "XXX"
    Public csbaData As DataSet
    Public Sub New()
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetData(ByVal myParam As String) As DataSet
        csbaData = New DataSet
        Dim connectionString As String = _connectionString
        Dim conn As New SqlConnection(connectionString)
        conn.Open()
        Try
            Dim command As New SqlCommand("SELECT * FROM MyTable", conn)
            command.CommandType = System.Data.CommandType.Text
            Dim da As New SqlDataAdapter(command)
            da.Fill(csbaData)
        Finally
            If Not IsNothing(conn) Then
                If conn.State <> ConnectionState.Closed Then
                    conn.Close()
                    conn.Dispose()
                End If
            End If
        End Try
        Return csbaData
    End Function
End Class


The error I get on the server:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 
OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.]
   System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type) +0
   System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase) +67
   System.Web.UI.Util.GetTypeFromAssemblies(IEnumerable assemblies, String typeName, Boolean ignoreCase) +146
   System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +8940004
   System.Web.UI.WebControls.ObjectDataSourceView.GetType(String typeName) +76
   System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1812
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   System.Web.UI.WebControls.GridView.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
   System.Web.UI.Control.EnsureChildControls() +102
   System.Web.UI.Control.PreRenderRecursiveInternal() +42
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

I know this isn't a memory issue because I can bind the grid using a SqlDataSource, but we really need to use the ObjectDataSource here. I'm also only loading 19 records to the grid.

Your help is greatly appreciated.

All times are GMT -5. The time now is 1:49 AM.
Previous Next