I have a unit with helper class (under the influence of you TBDESession):
Code: Select all
unit uSharedOraSession;
interface
uses
ORA, OraCall, DBAccess, classes, OraClasses, CRAccess;
type
TSharedOraSession = class(TOraSession)
protected
FpLDA : Pointer;
FpSVC : Pointer;
procedure DoConnect; override;
procedure DoDisconnect; override;
procedure SetIConnection(Value: TCRConnection); override;
public
constructor Create(Owner: TComponent; aLDA, aSVC : Pointer); reintroduce;
procedure CopyConnect(aSession: TOraSession);
end;
implementation
procedure TSharedOraSession.SetIConnection(Value: TCRConnection);
begin
inherited;
FIConnection := Value as TOCIConnection;
end;
procedure TSharedOraSession.DoConnect;
begin
if not OCIInited then
InitOCI;
CreateIConnection;
Pooling:=False;
if Options.UseOCI7 then
begin
FIConnection.SetOCICallStyle(OCI73);
FIConnection.SetLDA(FpLDA);
end
else
begin
FIConnection.SetOCICallStyle(OraCall.OCICallStyle);
FIConnection.SetSvcCtx(FpSVC)
end;
inherited;
end;
procedure TSharedOraSession.DoDisconnect;
begin
try
if Options.UseOCI7 then
FIConnection.SetLDA(nil)
else
FIConnection.SetSvcCtx(nil);
except
on E: EDAError do
begin
if not((csDestroying in ComponentState) and E.IsFatalError) then
Raise;
end
else
Raise;
end;
end;
constructor TSharedOraSession.Create(Owner: TComponent; aLDA, aSVC : Pointer);
begin
inherited Create(Owner);
FpLDA := aLDA;
FpSVC := aSVC;
ConnectPrompt := False;
Options.EnableIntegers := False;
Options.NeverConnect := True;
Options.UseOCI7 := not Assigned(aSVC);
end;
procedure TSharedOraSession.CopyConnect(aSession: TOraSession);
begin
if Assigned(aSession) then
begin
aSession.Options.UseOCI7 := Options.UseOCI7;
aSession.AssignConnect(Self);
end;
end;
end.
I have a form
Code: Select all
object DBGrid1: TDBGrid
DataSource = DataSource1
end
object Button1: TButton
OnClick = Button1Click
end
object OraSession1: TOraSession
Options.UseOCI7 = True
end
object OraSession2: TOraSession
Options.UseOCI7 = True
end
object OraQuery1: TOraQuery
Session = OraSession2
SQL.Strings = (
'select * from all_objects')
end
object DataSource1: TDataSource
DataSet = OraQuery1
end
And this working simple code for testing:
Code: Select all
with TSharedOraSession.Create(nil,OraSession1.LDA,nil) do
try
Connect;
CopyConnect(OraSession2);
Disconnect;
finally
Free;
end;
OraQuery1.Session:=OraSession2;
OraQuery1.Open;
This work very well in production with ODAC 4.05, 4.50, 6.50 (maybe 6.90) with a little changes(like
vs
etc). While you not changed initialization procedure.
Hope this sample is enough?