Subject | Re: [IBO] REPOST: exception handling suggestion |
---|---|
Author | d_dude_2003 |
Post date | 2007-01-30T08:24:18Z |
thanx Markus, i tried but it doesnt work.
here is my code:
==========================================
procedure TForm1.FormCreate(Sender: TObject);
begin
lblConnectionLost.Visible := False;
FReconnectThread := TReconnectThread.Create(Handle);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FReconnectThread.Terminate
end;
procedure TForm1.btnConnectClick(Sender: TObject);
begin
try
TheConnection.Protocol := cpTCP_IP;
TheConnection.Username := 'SYSDBA';
TheConnection.Password := 'masterkey';
TheConnection.DatabaseName := 'MyDB';
TheConnection.Server := '192.168.11.128';
TheConnection.Path := 'MyDB';
TheConnection.Connect;
except
on E: Exception do
ShowMessage(E.Message)
end;
end;
procedure TForm1.TheConnectionError(Sender: TObject;
const ERRCODE: Integer; ErrorMessage, ErrorCodes: TStringList;
const SQLCODE: Integer; SQLMessage, SQL: TStringList;
var RaiseException: Boolean);
begin
if IB_Session.ConnectionLostErrCode(ERRCODE) then
begin
lblConnectionLost.Visible := True;
FReconnectThread.Resume;
Abort
end
end;
procedure TForm1.btnOpenClick(Sender: TObject);
begin
tblUsers.Open
end;
procedure TForm1.btnCloseClick(Sender: TObject);
begin
tblUsers.Close
end;
procedure TForm1.WMWeAreLive(var Msg: TMessage);
begin
TheConnection.ForceDisconnect;
TheConnection.Connect;
lblConnectionLost.Visible := False;
end;
procedure TForm1.btnDisconnectClick(Sender: TObject);
begin
TheConnection.ForceDisconnect;
end;
procedure TForm1.btnAddClick(Sender: TObject);
begin
try
StoredProcedure.SQL.Clear;
StoredProcedure.StoredProcName := 'SP_USER_ADD';
StoredProcedure.ParamNames.Add('FIRST_NAME');
StoredProcedure.ParamNames.Add('LAST_NAME');
StoredProcedure.ParamNames.Add('LOGIN');
StoredProcedure.ParamNames.Add('PASSWD');
StoredProcedure.ParamNames.Add('DESCRIPTION');
StoredProcedure.ParamNames.Add('ACCT_DISABLED');
StoredProcedure.ParamNames.Add('CHANGE_PASSWD');
StoredProcedure.ParamNames.Add('EMAIL');
StoredProcedure.ParamNames.Add('FINGERPRINT');
StoredProcedure.ParamNames.Add('FINGERPRINT_IMG');
StoredProcedure.ParamNames.Add('PHOTO');
StoredProcedure.ParamNames.Add('CELLNUMBER');
StoredProcedure.ParamNames.Add('RECEIVETM');
StoredProcedure.Prepare;
StoredProcedure.ParamByName('FIRST_NAME').AsString := '111';
StoredProcedure.ParamByName('LAST_NAME').AsString := '222';
StoredProcedure.ParamByName('LOGIN').AsString := '333';
StoredProcedure.ParamByName('PASSWD').AsString := '444';
StoredProcedure.ParamByName('DESCRIPTION').AsString := '111F';
StoredProcedure.ParamByName('ACCT_DISABLED').AsString := 'F';
StoredProcedure.ParamByName('CHANGE_PASSWD').AsString := 'F';
StoredProcedure.ParamByName('EMAIL').AsString := '888@...';
StoredProcedure.ParamByName('CELLNUMBER').AsString := '999';
StoredProcedure.ParamByName('RECEIVETM').AsString := 'T';
TheTransaction.StartTransaction;
StoredProcedure.ExecProc;
TheTransaction.Commit;
except
on E: Exception do
begin
TheTransaction.Rollback;
if (E is EIB_ISCError) then
begin
if ConnectionLostErrcode(EIB_ISCError(E).ERRCODE) then
raise;
end;
end;
end;
end;
When i disconnect the server and click the Add button, it takes some
time and then exception is shown....
--- In IBObjects@yahoogroups.com, "Markus Ostenried" <macnoz@...>
wrote:
here is my code:
==========================================
procedure TForm1.FormCreate(Sender: TObject);
begin
lblConnectionLost.Visible := False;
FReconnectThread := TReconnectThread.Create(Handle);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FReconnectThread.Terminate
end;
procedure TForm1.btnConnectClick(Sender: TObject);
begin
try
TheConnection.Protocol := cpTCP_IP;
TheConnection.Username := 'SYSDBA';
TheConnection.Password := 'masterkey';
TheConnection.DatabaseName := 'MyDB';
TheConnection.Server := '192.168.11.128';
TheConnection.Path := 'MyDB';
TheConnection.Connect;
except
on E: Exception do
ShowMessage(E.Message)
end;
end;
procedure TForm1.TheConnectionError(Sender: TObject;
const ERRCODE: Integer; ErrorMessage, ErrorCodes: TStringList;
const SQLCODE: Integer; SQLMessage, SQL: TStringList;
var RaiseException: Boolean);
begin
if IB_Session.ConnectionLostErrCode(ERRCODE) then
begin
lblConnectionLost.Visible := True;
FReconnectThread.Resume;
Abort
end
end;
procedure TForm1.btnOpenClick(Sender: TObject);
begin
tblUsers.Open
end;
procedure TForm1.btnCloseClick(Sender: TObject);
begin
tblUsers.Close
end;
procedure TForm1.WMWeAreLive(var Msg: TMessage);
begin
TheConnection.ForceDisconnect;
TheConnection.Connect;
lblConnectionLost.Visible := False;
end;
procedure TForm1.btnDisconnectClick(Sender: TObject);
begin
TheConnection.ForceDisconnect;
end;
procedure TForm1.btnAddClick(Sender: TObject);
begin
try
StoredProcedure.SQL.Clear;
StoredProcedure.StoredProcName := 'SP_USER_ADD';
StoredProcedure.ParamNames.Add('FIRST_NAME');
StoredProcedure.ParamNames.Add('LAST_NAME');
StoredProcedure.ParamNames.Add('LOGIN');
StoredProcedure.ParamNames.Add('PASSWD');
StoredProcedure.ParamNames.Add('DESCRIPTION');
StoredProcedure.ParamNames.Add('ACCT_DISABLED');
StoredProcedure.ParamNames.Add('CHANGE_PASSWD');
StoredProcedure.ParamNames.Add('EMAIL');
StoredProcedure.ParamNames.Add('FINGERPRINT');
StoredProcedure.ParamNames.Add('FINGERPRINT_IMG');
StoredProcedure.ParamNames.Add('PHOTO');
StoredProcedure.ParamNames.Add('CELLNUMBER');
StoredProcedure.ParamNames.Add('RECEIVETM');
StoredProcedure.Prepare;
StoredProcedure.ParamByName('FIRST_NAME').AsString := '111';
StoredProcedure.ParamByName('LAST_NAME').AsString := '222';
StoredProcedure.ParamByName('LOGIN').AsString := '333';
StoredProcedure.ParamByName('PASSWD').AsString := '444';
StoredProcedure.ParamByName('DESCRIPTION').AsString := '111F';
StoredProcedure.ParamByName('ACCT_DISABLED').AsString := 'F';
StoredProcedure.ParamByName('CHANGE_PASSWD').AsString := 'F';
StoredProcedure.ParamByName('EMAIL').AsString := '888@...';
StoredProcedure.ParamByName('CELLNUMBER').AsString := '999';
StoredProcedure.ParamByName('RECEIVETM').AsString := 'T';
TheTransaction.StartTransaction;
StoredProcedure.ExecProc;
TheTransaction.Commit;
except
on E: Exception do
begin
TheTransaction.Rollback;
if (E is EIB_ISCError) then
begin
if ConnectionLostErrcode(EIB_ISCError(E).ERRCODE) then
raise;
end;
end;
end;
end;
When i disconnect the server and click the Add button, it takes some
time and then exception is shown....
--- In IBObjects@yahoogroups.com, "Markus Ostenried" <macnoz@...>
wrote:
>