内存异常 [英] Outof Memory Exception
问题描述
大家好,
基本上我正在尝试将数据从SQL Server迁移到SQLCe 4.0;这是一个正在进行的过程,这意味着产品版本化的数据库在SQL Server上管理,我需要在SQLce中为桌面应用程序创建一个表。
我在这里使用c#编写一个迁移,它将数据从SQL Server迁移到SQL Ce 4.0
以下是代码部分: -
//关注语句将数据从表中提取到Stringbuilder中。其中一个表包含大约1600000(十六个缺乏)行。
StringBuilder strStrings = GetDataToLoad(lstDestTableNeed.Items [z] .ToString(),DT,strCols);
当我尝试将字符串构建器转换为List时,它显示出内存异常,我尝试了以下三种方法。但没有运气。
// List< string> strQ = strStrings.ToString()。Split('|')。ToList();
// IEnumerable< string> strQ = strStrings.ToString()。Split('|')。AsEnumerable();
// var arrary = strStrings.ToString()。Split('|');
请帮帮我。
Hi All,
Basically i am trying to migrate data from SQL Server to SQLCe 4.0; It is an on going process, which means for product versionised DB is managed on SQL Server and i need to create a table in SQLce for desktop application.
Here i am using c# to write a migratory which is migrates data from SQL Server to SQL Ce 4.0
Following is code part:-
// Following statement pulls data from table into Stringbuilder. One of the table contains about 1600000 (Sixteen lack) rows.
StringBuilder strStrings = GetDataToLoad(lstDestTableNeed.Items[z].ToString(), DT, strCols);
When i am trying to convert string builder to List it is showing out of Memory exception, I have tried following three ways. But no luck.
// List<string> strQ = strStrings.ToString().Split('|').ToList();
// IEnumerable<string> strQ = strStrings.ToString().Split('|').AsEnumerable();
//var arrary = strStrings.ToString().Split('|');
help me please.
推荐答案
看起来你正在构建一个包含160万行格式化版本的字符串。考虑到.NET中没有对象的大小可能超过2GB,包括StringBuilder的内容,这可能是你的问题。或者生成的String对象比那个大。
一行一行地构建一行并将其传递给你需要的任何东西。不要构建包含160万行数据的数据的单个字符串!
It looks like you're building a string that contains some formatted version of 1.6 Million rows. Considering no object in .NET can be larger than 2GB in size, including the contents of a StringBuilder, this may be your problem. Or the resulting String object is bigger than that.
Build one line at a time row by row and pass it to whatever you need to. Do NOT build a single string that contains the data for 1.6 Million rows of data!
这篇关于内存异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!