I am using delphi 7 and oracle. I want to connect oracle dynamically through delphi using TADOConnection. I have created one form containing 3 edit box for server name,username, password and one button 'Connect'. I tried to connect statically by building ConnectionString. Now i am trying to connect on 'Connect' button click depending upon the user enter values in server,username and password. How can i do this. any suggestions. thanks for the help.
- IMHO should should better forget about using a ADO/OleDB connection with Oracle. There are severe problems with the providers from Microsoft or Oracle, about BLOBs and performance. Use instead direct OCI communication for lighter and faster access. See commercial versions like ODAC or our Open Source classes.Arnaud Bouchez– Arnaud Bouchez2011-09-14 16:48:56 +00:00Commented Sep 14, 2011 at 16:48
2 Answers
Assume that you already install the oracle client (Oracle Provide for OLEDB), have a working tnsnames, etc. So, for example, to connect to instance "ORCL" login as user "HR" with password "password", the connection string should be like :
Provider=OraOLEDB.Oracle.1;Data Source=ORCL;User ID=HR;Password=password
And taking the string from the component, it will looks like :
Procedure TForm1.Button1Click(Sender: TObject); begin ADOConnection1.ConnectionString:= 'Provider=OraOLEDB.Oracle.1;' + 'Data Source=' + Edit1.Text + ';' + 'Data Source=' + Edit2.Text + ';' + 'Password=' + Edit3.Text; ADOConnection1.LoginPrompt:= False; ADOConnection1.Connected:= True; end; Comments
You have to change the ConnectionString property of TAdoConnection component, you can get the right one from ConnectionStrings website
Here's the one for ADO connection with Microsoft provider:
Provider =msdaora; Data Source =MyOracleDB; User Id =myUsername; Password =myPassword; for the UserID & Password, you have to replace them with your Editboxes.
Update:
for code you write something like this:
AdoConnection.Close; AdoConnection.ConnectionString := format('Provider=msdaora; Data Source =MyOracleDB; User Id = %s; Password = %s',edtUserName.Text,edtPassword.Text]); '; AdoConnection.Open;