Oracle Database 12.1.0.1.0
I use OnError event of TOraSession object for handle ORA-28001 error and call TOraSession.ChangePassword
When click "OCI" button and enter oratest1/111 -> "OCI Connected"
When click "Direct" button and enter oratest2/111 -> "ORA-28040: No matching authentication protocol"
project1.sql
Code: Select all
create user oratest1 identified by "111" password expire default tablespace USERS temporary tablespace TEMP;
create user oratest2 identified by "111" password expire default tablespace USERS temporary tablespace TEMP;
grant connect to oratest1, oratest2;
Code: Select all
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 300
ClientWidth = 635
Color = clBtnFace
ParentFont = True
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 64
Top = 112
Width = 75
Height = 25
Caption = 'OCI'
TabOrder = 0
OnClick = Button1Click
end
object Button2: TButton
Left = 168
Top = 112
Width = 75
Height = 25
Caption = 'Direct'
TabOrder = 1
OnClick = Button2Click
end
object OraSession1: TOraSession
Username = 'ORATEST1'
Server = 'TEST'
OnError = OraSession1Error
Left = 96
Top = 16
end
object OraSession2: TOraSession
Options.Direct = True
Username = 'ORATEST2'
Server = 'test:1521:TEST'
OnError = OraSession2Error
Left = 176
Top = 16
end
end
Code: Select all
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, OraError, OraCall, Data.DB, DBAccess,
Ora, Vcl.StdCtrls, OdacVcl;
type
TForm1 = class(TForm)
OraSession1: TOraSession;
OraSession2: TOraSession;
Button1: TButton;
Button2: TButton;
procedure OraSession2Error(Sender: TObject; E: EDAError; var Fail: Boolean);
procedure OraSession1Error(Sender: TObject; E: EDAError; var Fail: Boolean);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
OraSession1.Connected := True;
ShowMessage('OCI Connected');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
OraSession2.Connected := True;
ShowMessage('Direct Connected');
end;
procedure TForm1.OraSession1Error(Sender: TObject; E: EDAError;
var Fail: Boolean);
begin
if (E is EOraError) and (EOraError(E).ErrorCode = 28001) then
begin
Fail := False;
OraSession1.ChangePassword('222');
end;
end;
procedure TForm1.OraSession2Error(Sender: TObject; E: EDAError;
var Fail: Boolean);
begin
if (E is EOraError) and (EOraError(E).ErrorCode = 28001) then
begin
Fail := False;
OraSession2.ChangePassword('222');
end;
end;
end.