2011-09-27 3 views
-2

안녕하세요 내 컴퓨터에서 잘 작동하지만 다음과 같은 코드가 있습니다. 다른 컴퓨터에서 설정을 설치하면 응용 프로그램이 손상되어 오류가 발생합니다.
그리고 내가 달성하려고하는 기능은 몇 가지 테이블에 대한 스키마와 데이터를 출력 폴더에 백업하고 사용자가 Schema_checkbox를 검사하면 백업 파일은 스키마까지 줄을 삭제하고 데이터 비트 만 남겨 두어야합니다. 결국에는 데이터가 포함되지만 스키마는 포함되지 않습니다. 이 비트는 내 컴퓨터에서 제대로 작동하지만 내 exe를 설치 한 지원 데스크에서는 작동하지 않습니다.다른 PC에서 작동하지 않습니다

내 코드 :

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 14시 46분 34초 시작 백업 테이블 데이터
27/09/2011 14시 46분 54초 예외 System.OutOfMemoryException :
'System.OutOfMemoryException'형식의 예외가 발생했습니다. System.String.GetStringForStringBuilder (문자열 값 INT32 시작 인덱스, INT32 길이 INT32 용량)에
System.Text.StringBuilder.Append에서 System.Text.StringBuilder.GetNewString (문자열 currentString, INT32 requiredLength)에서
(문자열 값) ErikEJ.SqlCeScripting.Generator.GenerateTableContent (문자열 TABLENAME, 부울 saveImageFiles) ErikEJ.SqlCeScripting.Generator.GenerateTableData (문자열 TABLENAME, 부울 saveImageFiles) ErikEJ.SqlCeScripting.Generator.GenerateTableScript에서
에서
(문자열에서
tableName, String outputFolder, Boolean isBackupReq) ErikEJ.SqlCeScripting.Generator.GenerateSchemaGraph (문자열 를 ConnectionString, List`1 테이블, 문자열 outputFolderPath, 부울 isDataBackupReq)에서
SqlDatabaseDataExport.MainForm.BackupScriptLocation()에서

+0

"System.OutOfMemoryException"- 응용 프로그램이 너무 많은 메모리를 사용 중입니다. 덜 오래된 컴퓨터에서 메모리 사용량을 줄이거 나 프로그램을 설치하십시오. – qJake

+4

포함 된 코드에서 예외가 발생하지 않습니다. 'CopyFileContent'는 스택 트레이스의 어디에도 나타나지 않습니다. –

+1

여기서 sb가 사용됩니까? – hungryMind

답변

1

파일 당신이하려고하면 열려면 시스템 용량이 부족한 한계에 도달 할 수 있습니다. 스트림을 열어 파일을 읽은 다음 다른 스트림을 사용하여 버퍼 (StringBuilder 사용)로 다른 파일에 쓸 것을 제안합니다. 이렇게하면 newText은 StringBuilder로 크기를 제어하기 때문에 매우 높은 수준의 메모리에 도달하지 않습니다. 또한 문자열이 많은 메모리를 사용하기 때문에 String 대신 StringBuilder를 사용하려면 많은 문자열을 연결할 때 항상 더 좋습니다. 제안이 끝나면 원본 파일을 삭제하고 첫 번째 파일의 이름으로 출력 파일의 이름을 변경하면됩니다. 그게 전부 야.

+1

좋은 조언을하지만, 그는 예외가 실제로 던져지고 찾을 스택 추적을 사용할 수 있습니다. –

+0

@Daok 원본 파일을 삭제하고 출력 파일의 이름을 바꿀 수있는 코드를 보내 주시겠습니까? – 62071072SP

+1

System.IO.File.Move (@ "C : \ From.txt", @ "C : \ TO.txt"); // 이름 바꾸기 –

관련 문제