Oracle error ORA-12154

Good day, dear forumchane.

There was a question about working with the Oracle Database from Visual Studio 2013 (C#). When trying to connect to the database, Oracle returns the following error:

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

Here is the connection code:

using System.Web.Mvc;
using Oracle.ManagedDataAccess.Client;


string oradb = "Data Source=WorkTest;User Id=C##;Password=123;";
            OracleConnection conn = new OracleConnection(oradb);  // C#
            conn.Open();
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            cmd.CommandText = "select * from ааа";
            cmd.CommandType = CommandType.Text;
            OracleDataReader dr = cmd.ExecuteReader();
            dr.Read();
            var cc = dr.GetString(0);
            conn.Dispose();

The error is thrown at the stage: conn.Open();.
According to the search results, it seems that the reason may be in the file tnsnames.ora. The file tnsnames.ora contains next:

# tnsnames.ora Network Configuration File: D:\app\username\product\12.1.0\dbhome_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.

LISTENER_WORKTEST =
  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))


ORACLR_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
    (CONNECT_DATA =
      (SID = CLRExtProc)
      (PRESENTATION = RO)
    )
  )

LISTENER_ORCL =
  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))


WORKTEST =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = WorkTest)
    )
  )

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

Tell me what and where to look... I've been hanging out for two days now. ((
(I haven't worked with Oracl until now:()

Here:

alt text

Does the server have such a sid WorkTest? Here:

alt text

Here is created with TNS, all prikonektilos:

alt text

Here is still tried through SQL PLUS prikonektitsya, like all broke a, but why something not pass team SQL, although and must:

alt text

Update

Yes, the thing is that I don't even know how to check half of the parameters: (

File sqlnet.ora contains

# sqlnet.ora Network Configuration File: D:\app\username\product\12.1.0\dbhome_1\network\admin\sqlnet.ora
# Generated by Oracle configuration tools.

# This file is actually generated by netca. But if customers choose to 
# install "Software Only", this file wont exist and without the native 
# authentication, they will not be able to connect to the database on NT.

SQLNET.AUTHENTICATION_SERVICES= (NTS)

NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)

Everything seems to be everywhere, but I don't know what to do(

And here is the solution to the problem:

I have already tried everything that is possible), yesterday I sat half the night. Here is who will be interested in the method of checking for this error in SQL Plus: https://www.youtube.com/watch?v=QVJ1xO2V7Dc. I followed it, and everything is fine. me, but through VS 2013 still brings down the error. But the reason, as always, was banal to the point of outrage:(, you must specify Data Source=localhost: 1521/WorkTest in the connection string instead of Data Source=WorkTest... and that's it!!!!... now only emotions:(.. and on the official site it is indicated that it is necessary to Data Source=WorkTest ... oh, thank you so much to everyone who helped). The issue is resolved, the project has passed)

Author: Alex_student, 2015-01-28

1 answers

Since you have a connection from SQL/Developer using the TNS protocol, it means that the problem is in C#.

Check the settings of the ORACLE_HOME and PATH environment variables. The PATH environment variable must specify the path where it lies oci.dll.

Try to find the source code of the program on github that is connected to the ORACLE database, and check how it works.

 2
Author: igaraev, 2015-01-29 07:27:35