0

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.

1
  • 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. Commented Sep 14, 2011 at 16:48

2 Answers 2

2

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; 
Sign up to request clarification or add additional context in comments.

Comments

0

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; 

8 Comments

after connection string to open Connection, we have to make ADOConnection.Connected:= true; right??
Do not use MS Oracle provider, as it supports only OCI7 and because that is limited in many ways. Use Oracle provider for Oracle.
And better to work with Oracle using 3d party libraries, like AnyDAC. Because ADO is limiting Oracle features.
@ oodesigner: I am unable to see any option like oracle provider for oracle. Need to install it?? I am currently using MSDAORA.
@Mohammed Nasman, yes, you need to download it from Oracle site and install. See the Hasan S answer.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.