ORA-28002 and ORA-28001 messages

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Yuvich

ORA-28002 and ORA-28001 messages

Post by Yuvich » Thu 13 Jan 2005 12:51

Hello,

How can I intercept the message ORA-28002 and process ORA-28001? Whether there is somewhere an example of it?

ODAC: 5.10.4.13 for Delphi 6
Oracle: 9.2.0.4

Thanks for you help.

Alex
Posts: 655
Joined: Mon 08 Nov 2004 08:39

Post by Alex » Thu 13 Jan 2005 15:22

You can use OnError event of your TOraSession object for such tasks, there you can intercept and handle necessary errors.
For example:

Code: Select all

 procedure TForm1.OraSession1Error(Sender: TObject; E: EDAError;
  var Fail: Boolean);
 begin
   if E.ErrorCode = 28002 then begin
     Fail:= false;
     raise EOraError.Create(28001,'ORA-28001: the password has expired'); // You must include OraError in your Uses clause to use EOraError.
   end;
 end;

Yuvich

Post by Yuvich » Fri 14 Jan 2005 13:40

The problem was solved as follows

Code: Select all

// interception of ORA-28002

procedure TForm1.OraSession1AfterConnect(Sender: TObject);
var
  Msg: string;

begin
  if OraSession.LastError = 28002 then
  begin
//  getting of the text with the amount of days
    OraCall.GetOraError(OCI_SUCCESS_WITH_INFO, Msg);

// procedure for password changing (described below)
    ChangePassword(OraSession, OraSession.LastError, Msg);

// the message is processed
    OraSession.LastError := 0;
  end;
end;

// processing of ORA-28001

procedure TForm1.OraSession1Error(Sender: TObject; E: EDAError; var Fail: Boolean);
begin
   if E.ErrorCode = 28001 then
    ChangePassword(OraSession, E.ErrorCode, E.Message);
end;

// procedure for password changing 

procedure ChangePassword(AnOraSession: TOraSession; ErrCode: integer; ErrMsg: string);
begin
    if MessageDlg(ErrMsg + #13'Change password?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
    begin

// form creating
      FRePass := TFRePass.Create(nil);

      if FRePass.ShowModal = mrOk then
      begin
          AnOraSession.ChangePassword(FRePass.edNewPass.Text);
      end;
    end
end;

Post Reply