Additional
dbCAP
AnyDAC
ThinDAC
NCOCI8
Topic: Connection to oracle
Connection to oracle
Posted: 2007/07/31 09:11
 
Hello,
i must connect to oracle db with anydac component but i want to use code to connect and not directly component tadconnection on the form but when i set connected:=true i have error.Someone can help me to post code to connect an oracle db?Where i set host and port?

Thanks and sorry for my bad english.
Re:Connection to oracle
Posted: 2007/07/31 09:36
 
Hello

Do you mean, to create TADConnection on fly (in code) and not to drop it onto form ? If yes, then use that:


 var   oConnTADConnection;   oQryTADQuery; ....   oConn := TADConnection.Create(nil);   oConn.Params.Add('DriverID=Ora');   oConn.Params.Add('Database=<TNS name>');   oConn.Params.Add('User_Name=<user name>');   oConn.Params.Add('Password=<user password>');   oConn.Connected := True;   oQry := TADQuery.Create(nil);   oQry.Connection := oConn;   oQry.SQL.Text := 'select * from mytable';   oQry.Open;



Regards,
Dmitry
Re:Connection to oracle
Posted: 2007/07/31 09:39
 
Thanks, but i 'm already test this code but when i set connected:=true delphi crash and send me an error.
Re:Connection to oracle
Posted: 2007/07/31 09:43
 
1) What is the error text ?
2) At which code line it happens ?
Re:Connection to oracle
Posted: 2007/07/31 09:54
 
it's return an access violation. If you want you cand send me an example to d.vitali74@tin.it

Thanks.

Post edited by: oinguino, at: 2007/07/31 09:58
Re:Connection to oracle
Posted: 2007/07/31 12:12
 
This code works for me. Pay attention to uses clause.


 uses   daADPhysOracldaADCompClientdaADGUIxFormsWait; {$R *.dfm} procedure TForm1.FormCreate(SenderTObject); var   oConnTADConnection;   oQryTADQuery; begin   oConn := TADConnection.Create(nil);   oConn.Params.Add('DriverID=Ora');   oConn.Params.Add('Database=');   oConn.Params.Add('User_Name=addemo');   oConn.Params.Add('Password=a');   oConn.Connected := True;   oQry := TADQuery.Create(nil);   oQry.Connection := oConn;   oQry.SQL.Text := 'select * from all_tables';   oQry.Open; end;