我的.aspx页面之一显示错误消息:抛出了类型'System.OutOfMemoryException'的异常

问题描述 投票:0回答:1

在我的ViewProducts.aspx,我有一个基于GridviewSELECT * FROM Product。而Product表有553行。

因此,现在当我尝试显示ViewProducts.aspx页面时,我收到以下错误:

描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.OutOfMemoryException:抛出了类型'System.OutOfMemoryException'的异常。

来源错误:

在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。

堆栈跟踪:

[OutOfMemoryException:抛出了类型'System.OutOfMemoryException'的异常。] 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

这是我的web.config文件:

<?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>

有一件事我确认正在显示错误消息,因为ViewProducts.aspx页面试图显示553行的网格视图,这超出了系统的容量。

但是,我不确定我必须在web.config文件中做出哪些确切的更改。

如果提供建议的建议或解决方案,将会有所帮助。

c# asp.net sql-server visual-studio-2015 iis-10
1个回答
1
投票

您的web.config文件通常看起来很好。您正在使用进程会话(sessionState mode =“InProc”)。这将消耗内存,并且不清楚您正在使用的提供程序是否正在执行任何低效操作。使用数据库存储会话可能会有所帮助,但是会导致网络延迟。

其他想法:你应该避免在查询中做SELECT *。只需拉入您真正需要的列。如果您的应用程序使用分页,请考虑仅提取您需要显示的行(数据虚拟化)。还要验证您没有在数据绑定中执行任何不需要的操作。最后,如果服务器功能不足,请扩展您的服务器。 500多行不是很多。如果您遇到内存不足异常,请确保您的系统没有运行不必要的进程。

© www.soinside.com 2019 - 2024. All rights reserved.