简体   繁体   English

system.dll中的异常“ System.OutOfMemoryException”

[英]Exception 'System.OutOfMemoryException' in system.dll

I am trying to select all the columns in my table which have about 2.5million records. 我试图选择表中所有具有约250万条记录的列。

But it throws me the above exception after some time of execution.How to solve this problem 但是在执行了一段时间后,我抛出了上面的异常。如何解决这个问题

adapter.SelectCommand = new SqlCommand("SELECT * from Dwh_staging_table", con1);
adapter.Fill(DataSet2, "Transformed_Table");

I guess you are dealing with some custom build Data Warehouse solution, that means huge amounts of data. 我猜您正在处理一些自定义构建的数据仓库解决方案,这意味着大量的数据。 Whatever you try to do, you shouldn't be loading all the data from database to application in order to calculate some numbers in staging table. 无论您尝试做什么,都不应将所有数据从数据库加载到应用程序,以便在登台表中计算一些数字。

The best thing you can do is to calculate whatever you need before you put data to Dwh_staging_table, so the problem is solved before it happens. 最好的办法是在将数据放入Dwh_staging_table之前计算所需的任何内容,这样问题就可以在发生之前得到解决。 If this it not possible and you already loaded data to database, you should do all the processing in place, in database (eg using hated Stored Procedures). 如果这不可能,并且您已经将数据加载到数据库,则应该在数据库中进行所有适当的处理(例如,使用讨厌的存储过程)。

In general, when you are dealing with huge amounts of data, moving the data around is your biggest enemy. 通常,当您处理大量数据时,移动数据是您的最大敌人。 Try to solve all your problems at the place where the data are now, without unnecessary transfer. 尝试在现在的数据位置解决所有问题,而不必进行不必要的传输。

If you want to anyway load the data back to c# code (what I don't advice), try to do everything without materialising all the data in memory. 如果您仍然要将数据加载回c#代码(我不建议这样做),请尝试做所有事情而不在内存中实现所有数据。 Create repository function which returns IEnumerable, which will be internally using yield return, so the whole collection of data is never materialised. 创建返回IEnumerable的存储库函数,该函数将在内部使用yield return,因此永远不会实现整个数据集合。

And if you still insist on materializing data in some collection (what I don't advice even more), look at some collections which are not using sequential blocks of memory. 而且,如果您仍然坚持在某些集合中实现数据(我不建议更多),请查看一些未使用顺序内存块的集合。 Using collections like array, List or DataSet will result in higher chance of out of memmory exception. 使用数组,列表或数据集之类的集合将导致出现内存异常的可能性更高。 Try to use something like LinkedList or even better some chunked LinkedList of arrays (almost like paging which was suggested in other post). 尝试使用诸如LinkedList之类的东西,或者甚至更好地使用一些分块的LinkedList数组(几乎类似于其他文章中建议的分页)。

EDIT: From what you said 编辑:从你所说的

i have some missing values in the table i want to fill some columns afterwards using the avg techninque 我在表格中有一些缺失的值,之后我想使用avg技术填充一些列

it sounds to me like something what should be possible just by one UPDATE statement of the staging table in database. 在我看来,仅通过数据库中登台表的一条UPDATE语句就应该可以实现。 Not sure what exactly you want (eg I want to set to AvgMetric averaged value of Metric column grouped over Category column). 不知道您到底想要什么(例如,我想将“ Metric”列的平均值设置为“ Category”列中的分组)。 In that case it would look like: 在这种情况下,它看起来像:

WITH t AS (
SELECT st.[Category]
      ,st.[AvgMetric]
      ,AVG(st.[Metric]) OVER (PARTITION BY [st.Category] AS [CalculatedAvgMetric]
  FROM [Dwh_staging_table] st
)
UPDATE t
   SET [AvgMetric] = [CalculatedAvgMetric]

The obvious answer would be to reduce the data set returned. 显而易见的答案是减少返回的数据集。 Do you need all the columns? 您是否需要所有列?

How about paging the data? 如何分页数据? Check out the row_number() function. 检出row_number()函数。

使用自定义分页一次仅获取有限的记录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 引发异常:System.Drawing.dll中的“ System.OutOfMemoryException” - Exception thrown: 'System.OutOfMemoryException' in System.Drawing.dll 类型为“ System.OutOfMemoryException”的异常 - There was an exception of type 'System.OutOfMemoryException' 异常:抛出 System.OutOfMemoryException - Exception: System.OutOfMemoryException was thrown System.OutOfMemoryException:angularjs中抛出了类型'System.OutOfMemoryException'的异常 - System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown in angularjs 类型'System.OutOfMemoryException'的异常 - An exception of type 'System.OutOfMemoryException' 抛出异常:ZeroMQ.dll 中的“System.OutOfMemoryException” - Exception thrown: 'System.OutOfMemoryException' in ZeroMQ.dll System.OutOfMemoryException:抛出了“System.OutOfMemoryException”类型的异常 - System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown “system.outofmemoryexception”类型的 Visual Studio 异常 - Visual Studio exception of type 'system.outofmemoryexception' 抛出了类型'System.OutOfMemoryException'的异常 - Exception of type 'System.OutOfMemoryException' was thrown System.Drawing.dll中发生类型为'System.OutOfMemoryException'的未处理异常 - An unhandled exception of type 'System.OutOfMemoryException' occurred in System.Drawing.dll
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM