0
votes

In my ViewProducts.aspx, I have a Gridview based on SELECT * FROM Product. And the Product table has 553 rows.

Therefore, now when I try to show the ViewProducts.aspx page, I get the following error:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.

Source Error:

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.

Stack Trace:

[OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.] System.IO.MemoryStream.set_Capacity(Int32 value) +89 System.IO.MemoryStream.EnsureCapacity(Int32 value) +90 System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count) +326 Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.ArteryFilter.Write(Byte[] buffer, Int32 offset, Int32 count) +62 System.Web.HttpWriter.FilterIntegrated(Boolean finalFiltering, IIS7WorkerRequest wr) +9871464 System.Web.HttpResponse.FilterOutput() +104 System.Web.CallFilterExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +58 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +48 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +71

And this is my web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </configSections>
    <connectionStrings>
        <add name="DefaultConnection" 
             connectionString="Data source=LAPTOP-ODS96MIK\\MSSQL2014; database = Grocery_Demo; integrated security=SSPI"
             providerName="System.Data.SqlClient" />
        <add name="Grocery_DemoConnectionString" 
             connectionString="Data Source=LAPTOP-ODS96MIK\MSSQL2014;Initial Catalog=Grocery_Demo;Integrated Security=True"
             providerName="System.Data.SqlClient" />
    </connectionStrings>
    <system.web>
        <authentication mode="None" />
        <compilation debug="true" targetFramework="4.5.2" />
        <httpRuntime maxRequestLength="1048576" executionTimeout="3600" targetFramework="4.5.2" />
        <pages>
            <namespaces>
                <add namespace="System.Web.Optimization" />
                <add namespace="Microsoft.AspNet.Identity" />
            </namespaces>
            <controls>
                <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
            </controls>
        </pages>
        <membership>
            <providers>
                <clear />
            </providers>
        </membership>
        <profile>
            <providers>
                <clear />
            </providers>
        </profile>
        <roleManager>
            <providers>
                <clear />
            </providers>
        </roleManager>
        <sessionState mode="InProc" customProvider="DefaultSessionProvider">
            <providers>
                <add name="DefaultSessionProvider" 
                     type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
                     connectionStringName="DefaultConnection" />
            </providers>
        </sessionState>
    </system.web>
    <system.webServer>
        <security>
            <requestFiltering>
                <requestLimits maxAllowedContentLength="1073741824" />
            </requestFiltering>
        </security>
        <modules>
            <remove name="FormsAuthentication" />
        </modules>
    </system.webServer>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
                <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="EntityFramework"  publicKeyToken="b77a5c561934e089" />
                <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.Owin" culture="neutral" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.Owin.Security.OAuth" culture="neutral" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
            </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.Cookies" culture="neutral" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" culture="neutral" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
        </dependentAssembly>
    </assemblyBinding>
    </runtime>
    <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
            <parameters>
                <parameter value="mssqllocaldb" />
            </parameters>
         </defaultConnectionFactory>
         <providers>
             <provider invariantName="System.Data.SqlClient" 
                       type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
    </entityFramework>
    <system.codedom>
        <compilers>
            <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
           <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
        </compilers>
    </system.codedom>
</configuration>

One thing I confirmed that the error message is being displayed because the ViewProducts.aspx page is trying to display a gridview of 553 rows which is going beyond system's capacity.

But, I'm not sure regarding what are the exact changes I have to make in the web.config file.

It would be helpful if the recommended advice or solution is provided.

1
It could be the PageInspector as seen in the stack trace - Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracingstuartd
It would be awesome if you could provide a minimal reproducible example.mjwills

1 Answers

1
votes

Your web.config file generally looks fine. You're using in process sessions (sessionState mode="InProc"). This will consume memory, and it's not clear if the provider you're using is doing anything inefficient. Using a database to store session may help, but you will incur network latency.

Other thoughts: you should avoid doing SELECT *'s in your queries. Only pull in columns you really need. If your application is using pagination, consider pulling in only the rows you need to display (data virtualization). Also verify you're not doing anything not needed in your data binding. Lastly, scale up your server if its under powered significantly. 500+ rows is not a lot. If you're getting an out of memory exception, make sure your system isn't running unnecessary processes.