제목 그대로
오라클 테이블에 트랜잭션걸고 insert 할때 오류발생하면 오류로그를 작성한후 문제가 되는
해당 레코드를 넘어서 계속 insert진행하고 싶습니다.-_-;;
제가 짠 소스는 프로그램이 진행하다가 오류를 만나면 그냥 멈춰버려요..
고수님들의 가르침을 주세요...-_-;;;
procedure TForm1.Button2Click(Sender: TObject);
var
Row,max : integer;
LogFileName,ErrMsg : string;
ErrLogFile: TextFile;
begin
try
try
SendMessage(progressbar1.Handle, PBM_SETBARCOLOR, 0, clGreen);
if MessageDlg('저장하시겠습니까?', mtwarning,[mbYes, mbNo], 0) = mrYes then begin
//트랜잭션 시작
Database1.StartTransaction;
For Row := 1 to StringGrid1.RowCount-1 do begin
Query3.Close;
Query3.SQL.Clear;
Query3.SQL.BeginUpdate;
Query3.SQL.Add('Insert into upTABLE(no, xxx, yyy)');
Query3.SQL.Add(' values (:no, :xxx, :yyyy)');
Query3.SQL.EndUpdate;
Query3.ParamByName('no').asinteger := max+Row;
Query3.ParamByName('xxx').asstring := UpperCase(Trim(stringgrid1.Cells[1, Row]));
Query3.ParamByName('yyy').asstring := Trim(stringgrid1.Cells[2, Row]);
Query3.Prepare;
Query3.ExecSQL;
end; // For end
showmessage('업데이트 되었습니다.');
Database1.Commit;
Exit;
end
else
showmessage('취소하셨습니다.!!'); // if end
Exit;
except
on err:exception do
begin
LogFileName := ExtractFilePath(Application.ExeName)
+ ExtractFileName(Application.ExeName) + '_' +FormatDateTime('yyyy"년"mm"월"dd"일"',Now) + '.log';
// 민약, 에러로그가 없으면 에러로그 파일을 생성
if Not FileExists(LogFileName) then FileClose(FileCreate(LogFileName));
ErrMsg := '[' + FormatDateTime('YYYY:MM:DD:HH:NN', Now) + '] [' + Format('%-9s', [Screen.ActiveForm.Name]) +'] ['+ ExtractFileName(label3.Caption) +'] /';
AssignFile(ErrLogFile, LogFileName);
Append(ErrLogFile);
Writeln(ErrLogFile, ErrMsg+' '+inttostr(Row)+' 행 데이타 저장오류 -'+err.message);
ShowMessage(inttostr(Row)+' 행에서 작업이 중지되었습니다. Data확인요망-'+err.message);
Database1.Rollback;
Exit;
end;
end;
finally
Query1.Close;
Query2.Close;
Query3.Close;
CloseFile(ErrLogFile);
end;
end;
|