Good day, dear forum users.
There was a question about working with Oracle Database from Visual Studio 2013 (C #).
When trying to connect to the database Oracle gives 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 aaa"; cmd.CommandType = CommandType.Text; OracleDataReader dr = cmd.ExecuteReader (); dr.Read (); var cc = dr.GetString (0); conn.Dispose ();
The error crashes at the stage:
conn.Open (); .
According to the search results, it seems like the reason may be in the
tnsnames.ora file. The
tnsnames.ora file contains the following:
# 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 … otherwise I’ve been hanging out for the second day. ((
(I haven’t worked with Oracl until now :()
Does the server have such a sid WorkTest?
I created it with TNS, everything was connected:
I also tried to connect through SQL PLUS, it seemed like everything worked out, but for some reason the SQL commands do not pass, although they should:
Yes, the fact of the matter is that I don’t even know how to check half of the parameters 🙁
# 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)
like everything is everywhere, but I don’t know what to do (
and here is the solution to the problem:
I have already tried everything I can), I sat at midnight yesterday. If anyone is interested, the method for checking this error in SQL Plus: https://www.youtube. com / watch? v = QVJ1xO2V7Dc . I walked along it, and everything is fine with me, but through VS 2013 it still brings down an error. But the reason, as always, turned out to be banal to the point of disgrace :(, you need to specify Data Source = localhost: 1521 / WorkTest in the connection string instead of Data Source = WorkTest … and that’s it !!!! … now there are only emotions :(. . and on the office site it is indicated that Data Source = WorkTest is needed … eh Many thanks to everyone who helped). The issue is resolved, the connection passed)
Answer 1, authority 100%
Since you have a connection from SQL / Developer via the TNS protocol,
then the problem is in C #.
Check the settings for the ORACLE_HOME and PATH environment variables.
The PATH environment variable must contain the path where oci.dll is located.