0

I need to connect to remote oracle db from c# code. Client has a PL/SQL Developer installed and working, it should help me find out settings for my custom application.

The question is: How can I get connection string from PL/SQL Developer?

2
  • 1
    A very important question is what version of .NET framework are you using? Prior to 4.0, you could use System.Data.OracleClient, but now you have to go with a third party provider. I tend to use ODP.NET by Oracle for projects of .NET framework 4.0 or greater. Commented Jul 3, 2013 at 15:54
  • it doesn't matter) I can use ODP.NET. Commented Jul 3, 2013 at 15:56

2 Answers 2

3

If you are using ODP.NET use the following connection string

     string _ConnectionString = "Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)
(HOST = " + _host + ")(PORT = " + _port + "))(CONNECT_DATA = (SERVER = DEDICATED)
(SERVICE_NAME = " + _database + ")));Password=" + _password + ";User ID=" + _user;

If the connection works from sql developer, Right click on the connection name it will open the window as below

enter image description here

Replace _host with Hostname vale, _port with Port value, _database with SID, _user with Username and _password with Password values from sql properties box in the above c# connection string.

Sign up to request clarification or add additional context in comments.

Comments

1

http://www.connectionstrings.com is a great resource to look up connection strings between various languages and databases. http://www.connectionstrings.com/oracle, more specifically, has the connection string information you're looking for.

3 Comments

I need a certain string not a general one.
Dim oradb As String = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=YOUR_HOST_ADDRESS)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=YOUR_SERVICE_NAME)));User Id=YOUR_USER_NAME;Password=YOUR_PASSWORD;" This is what I use with ODP.NET to connect to PlSQL in .NET 4.0 projects. Hope that helps. Just replace the parts that start with YOUR_ with their corresponding info, and the connection object (once you reference ODP.NET) is OracleConnection(connection_string).
Maybe I have misunderstood the question: if you don't know the exact data that you need to complete a connection string (user id, password, host), search the computer for a file called "tnsnames.ora". That will hold all of the data you need - except the password.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.