【问题标题】:System.OutOfMemoryException even though we have lots of RAM [closed]System.OutOfMemoryException 即使我们有很多 RAM [关闭]
【发布时间】:2013-01-13 17:01:25
【问题描述】:

我正在运行带有 Windows 7 PRO 和 64 GB RAM 的 SQL Server 2012 开发人员版。

当我们执行大量内存请求时,会抛出 System.OutOfMemoryException。

是否有允许 SQL 使用更多物理 RAM 的快速修复方法?

代码:

// int count = MAX_BARS_IN_MEMORY / tf.timeperiod + 1;
                    hCommandBars.CommandText = String.Format(@"SELECT top " +     MAX_BARS_IN_MEMORY + " * FROM {0} WHERE {0}.timeperiod = " + tf.timeperiod + " ORDER BY     {0}.bartime desc", tableName);
                    barTimesAdapter = new SqlDataAdapter(hCommandBars);
                    barTimesAdapter.Fill(dTimeset);
                    foreach (DataTable table in dTimeset.Tables)
                    {
                        if (table.Rows.Count > 0)
                        {

                            foreach (DataRow row in table.Rows)
                            {
                                InMemoryTable inMemorytable = new InMemoryTable();
                                inMemorytable.BarTime = Convert.ToDateTime((row["bartime"].ToString()));
                                inMemorytable.High = Convert.ToDouble(row["high"].ToString());
                                inMemorytable.Low = Convert.ToDouble(row["low"].ToString());
                                inMemorytable.Open = Convert.ToDouble(row["open"].ToString());
                                inMemorytable.Close = Convert.ToDouble(row["close"].ToString());
                                inMemorytable.C1 = Convert.ToDouble(row["c1"].ToString());
                                inMemorytable.C2 = Convert.ToDouble(row["c2"].ToString());
                                inMemorytable.SNR2 = false;
                                inMemorytable.Symbol = symbol.Key;//symbol name
                                inMemorytable.TimePeriod = Convert.ToInt32(row["timeperiod"].ToString());

                                _SessAndBarTableList.Add(inMemorytable);
                            }
                        }
                    }
                    dTimeset.AcceptChanges();
                    dTimeset.Clear();
                }





            hConnectionBars.Close();
            hConnectionBars.Dispose();
            hConnectionBars = null;
        //});
        }

         _SessAndBarTableList = _SessAndBarTableList.OrderBy(x => x.BarTime).ToList();
         _1MinuteTableList = _1MinuteTableList.OrderBy(x => x.BarTime).ToList();
    }

【问题讨论】:

  • 您知道 CLR 有一个对象大小限制.. ?
  • 当“我们做了很多内存请求”时,请修复 OOME?您在问题中投入大量信息/努力并不容易。
  • 你能给我们更多的信息吗?
  • 我们回顾一下 "static string DATE_TO_LOOK_BACK_IN_MEMORY = "2012-12-16 00:00:00.000" 当我们保持日期接近今天时,它工作正常。当我们想要加载一个几个月后,我们得到了例外。我知道这是一个低层次的解释,但我目前只知道这些。
  • 1.5GB 看起来接近 .NET Framework 允许您在 32 位进程中使用的限制。 msdn.microsoft.com/en-us/library/ee815708.aspx 在 .NET Framework 应用程序中,公共语言运行时将托管堆的总大小限制为略小于进程地址空间的专用区域部分最大大小的一半。对于在 32 位机器上运行的 32 位进程,2 GB 表示进程地址空间的私有部分的上限。

标签: c# sql windows-7


【解决方案1】:

一种解决方案是使用SqlDataReader 而不是DataSet。这将阻止您从服务器中获取一大块的所有数据,这可能会解决问题。但是,如果您要返回很多行,您可能仍会遇到向表添加项目的问题。

这些大查询返回了多少行?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-26
    • 2017-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-11
    • 1970-01-01
    • 2021-05-23
    相关资源
    最近更新 更多