嗨,我有下面的代碼,它可以在我的機器上正常工作,但是當我給我的安裝設置在其他機器上應用程序已崩潰,並給我錯誤。
而我試圖實現的功能是我支持少量表的模式和數據到輸出文件夾,並且如果用戶檢查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