嗨,我有下面的代码,它可以在我的机器上正常工作,但是当我给我的安装设置在其他机器上应用程序已崩溃,并给我错误。
而我试图实现的功能是我支持少量表的模式和数据到输出文件夹,并且如果用户检查Schema_checkbox,那么备份文件应该删除行,直到模式并保留数据位。所以最后它会包含数据而不是模式。这个位在我的机器上工作正常,但没有安装我的exe文件。不能在其他电脑的工作
我的代码:
if (Schema_checkbox.Checked)
{
DisplayMainWindow("Schema not required selected");
Logger.Log("Schema not required selected " + DateTime.Now);
FileHelper.CopyFileContent(outputFileName);
DisplayMainWindow(" Only table data is backup excluding schema");
Logger.Log(" Only table data is backup excluding schema" + DateTime.Now);
}
public void CopyFileContent(string filePath)
{
try
{
StringBuilder sb = new StringBuilder();
string newText = null;
using (StreamReader tsr = new StreamReader(filePath))
{
do
{
string textLine = tsr.ReadLine() + "\r\n";
{
if (textLine.StartsWith("INSERT INTO"))
{
newText += textLine + Environment.NewLine;
}
}
}
while (tsr.Peek() != -1);
tsr.Close();
}
File.WriteAllText(filePath, newText);
}
catch (Exception ex)
{
Logger.Log("Exception" + ex);
MessageBox.Show("Error Occured" + ex);
}
}
错误消息:
27/09/2011十四时46分34秒开始备份表数据
27/09/2011 14时46分54秒的异常是:System.OutOfMemoryException:
引发类型'System.OutOfMemoryException'的异常。
在System.String.GetStringForStringBuilder(字符串值,的Int32 的startIndex,的Int32长度,的Int32容量)
在System.Text.StringBuilder.GetNewString(字符串currentString,的Int32 requiredLength)在System.Text.StringBuilder.Append(字符串值)
在ErikEJ.SqlCeScripting.Generator.GenerateTableContent(字符串表名, 布尔saveImageFiles)
在ErikEJ.SqlCeScripting.Generator.GenerateTableData(字符串表名, 布尔saveImageFiles)
在ErikEJ.SqlCeScripting.Generator.GenerateTableScript(字符串tableName, String outputFolder,Boolean isBackupReq)
在ErikEJ.SqlCeScripting.Generator.GenerateSchemaGraph(字符串 的connectionString,List`1表,字符串outputFolderPath,布尔 isDataBackupReq)
在SqlDatabaseDataExport.MainForm.BackupScriptLocation()
“System.OutOfMemoryException” - 您的应用程序使用的内存太多。减少内存使用量或将程序安装在不太“过时”的计算机上。 – qJake
您包含的代码中不会发生异常。 'CopyFileContent'不出现在堆栈跟踪的任何地方。 –
在哪里使用sb? – hungryMind