3

I am trying to connect Oracle 11g from C#. I have followed [this link], defined the connection allias like this:

moviess =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = xe)
    )
  )

When trying to connect using server explorer in Visual studio it gives me the following error : enter image description here

Here is the installation directory of the Oracle Developer Tool for Visual Studio. enter image description here

Where am I going wrong ? Kindly assist me.

user1584253
  • 975
  • 2
  • 18
  • 55
  • Where did you put the connection identifier? I think C# by default has some trouble finding TNSNames.ora, unless you tell it where it is, or set the connection string without using TNSNames. – GolezTrol Jul 26 '15 at 21:08
  • possible duplicate of [How to set proper path to TNSNAMES file in C# application?](http://stackoverflow.com/questions/10618512/how-to-set-proper-path-to-tnsnames-file-in-c-sharp-application) – GolezTrol Jul 26 '15 at 21:09
  • Did you install the visual studio stuff from Oracle? I normally have more options and things to fill out.. not sure... – CularBytes Jul 26 '15 at 21:32
  • show your connection string after removing password etc. Refer this link: http://stackoverflow.com/questions/820440/oracle-connection-string-without-tnsnames-ora-file – Rex Jul 28 '15 at 20:58

3 Answers3

2

This is the problem:

ORA-12154: TNS: Could not resolve the connect identifier specified

This is the cause:

https://docs.oracle.com/cd/B19306_01/server.102/b14219/net12150.htm

ORA-12154: TNS:could not resolve the connect identifier specified

Cause: A connection to a database or other service was requested using a connect identifier, and the connect identifier specified could not be resolved into a connect descriptor using one of the naming methods configured.

For example, if the type of connect identifier used was a net service name then the net service name could not be found in a naming method repository, or the repository could not be located or reached.

Action:

- If you are using local naming (TNSNAMES.ORA file):

- Make sure that "TNSNAMES" is listed as one of the values of the NAMES.DIRECTORY_PATH parameter in the Oracle Net profile (SQLNET.ORA)

- Verify that a TNSNAMES.ORA file exists and is in the proper directory and is accessible.

- Check that the net service name used as the connect identifier exists in the TNSNAMES.ORA file.

Q: Is Oracle 11g actually installed on your local PC? If not, you cannot use "localhost". You must also install the Oracle client.

Relevant links:

Community
  • 1
  • 1
paulsm4
  • 114,292
  • 17
  • 138
  • 190
2

You can use Oracle ODP.Net Driver from NuGet.

You can try these:

  1. Right-click on References and hit Manage NuGet packages.
  2. Select Official Oracle ODP.Net, Managed Driver

enter image description here

  1. Reference "Oracle.ManagedDataAccess.Client"
  2. Invoke the actual connection.

Here's the sample code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Oracle.ManagedDataAccess.Client;

namespace SampleOracle
{
    class Program
    {
        static void Main(string[] args)
        {
            OracleConnection connection = new OracleConnection();
            connection.ConnectionString = "User Id=<username>;Password=<password>;Data Source=<data source>"; //Data Source Format -> //IP_HOST:PORT/SERVICE_NAME e.g. //127.0.0.1:1521/Service_Name
            connection.Open();
            Console.WriteLine("Connected to Oracle" + connection.ServerVersion);           
        }
    }
}

Sample output:

enter image description here

Hope this helps!

Kent Aguilar
  • 5,048
  • 1
  • 33
  • 20
0

To reach your Add Connection window, you must have gone through this window first, right?

enter image description here

The message is pretty clear. The provider you are trying to use is deprecated and doesn't support Oracle 11.

As recommended, consider downloading and installing Oracle Developer Tools for Visual Studio instead.

EDIT: I completely forgot to mention this very important tidbit for when you do get this working: Do not use sys to connect to the Oracle database for your development. The sys user is very special and should only be used when absolutely necessary. Instead, create a separate user, and use that for your development.

sstan
  • 35,425
  • 6
  • 48
  • 66
  • I have installed Oracle Developer Tools for Visual Studio. What do I do next? How will Visual Studio know that its installed and from where do I get the connection string for oracle? – user1584253 Jul 28 '15 at 20:46