System.OutOfMemoryException即使我们有很多RAM

时间:2013-01-30 00:13:39

标签: c# sql windows-7

我正在运行带有Windows 7 PRO和64 GB RAM的SQL Server 2012 Developer Edition。

当我们执行大量内存请求时,我们得到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();
    }

1 个答案:

答案 0 :(得分:1)

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

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