在我的ViewProducts.aspx
中,我有一个基于SELECT * FROM Product
的Gridview
。Product
表有553行。
因此,现在当我尝试显示ViewProducts.aspx
页面时,我得到以下错误:
说明:当前web请求执行过程中发生未处理异常。请查看堆栈跟踪,以了解有关错误的更多信息以及错误在代码中的来源。
异常详细信息: System.OutOfMemoryException:引发了'System.OutOfMemoryException‘类型的异常。
源错误:
在执行当前web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的来源和位置的信息。
堆栈跟踪:
OutOfMemoryException:引发了'System.OutOfMemoryException‘类型的异常。System.IO.MemoryStream.set_Capacity(Int32值) +89 System.IO.MemoryStream.EnsureCapacity(Int32值) +90 System.IO.MemoryStream.Write(Byte[]缓冲器,Int32偏移量,Int32计数) +326 Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.ArteryFilter.Write(Byte[]缓冲器,finalFiltering偏移量,Int32计数) +62 System.Web.HttpWriter.FilterIntegrated(Boolean finalFiltering,布尔wr) +9871464 System.Web.CallFilterExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +58 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep步长+48 System.Web.HttpApplication.ExecuteStep(IExecutionStep步长,布尔值& 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=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
</configuration>
我确认显示错误消息的原因之一是ViewProducts.aspx
页面试图显示553行的网格视图,这超出了系统的容量。
但是,我不确定我必须在web.config文件中进行哪些确切的更改。
如果提供推荐的建议或解决方案,将会很有帮助。
发布于 2018-08-31 08:03:27
您的web.config文件通常看起来没有问题。您正在使用的进程内会话(sessionState mode="InProc")。这将消耗内存,并且不清楚您正在使用的提供程序是否在做一些低效的事情。使用数据库存储会话可能会有所帮助,但会导致网络延迟。
其他想法:你应该避免在你的查询中做SELECT *。只拉入你真正需要的列。如果你的应用程序使用分页,考虑只拉入你需要显示的行(数据虚拟化)。还要验证你没有在数据绑定中做任何不需要的事情。最后,如果你的服务器动力明显不足,请扩展你的服务器。500+行不是很多。如果你得到一个内存不足的异常,请确保你的系统没有运行不必要的进程。
https://stackoverflow.com/questions/52106785
复制相似问题