ORA-12545: connection failed because the target host or object does not exist - there is no error in System.Data.OracleClient

I canโ€™t believe that I need to ask this question, but I canโ€™t let my life connect to the Oracle 11g database.

When using System.Data.OracleClient , the following is true, but obviously this is depreciating. When using the same code, but using Oracle.DataAccess.OracleClient , I get the following error:

 {"ORA-12545: Connect failed because target host or object does not exist"} 

Here is my code

 using (OracleConnection con = new OracleConnection("Data Source=orac;User Id=SYSTEM; Password=Pass;")) { con.Open(); Console.WriteLine("Connection opened"); OracleCommand cmd2 = new OracleCommand("SELECT * FROM SYSTEM.TABLE", con); OracleDataReader oracleDataReader = cmd2.ExecuteReader(); while (oracleDataReader.Read()) { Console.WriteLine(oracleDataReader[0]); } } 

Can someone help me with what I am doing wrong?

I had to change the program to 32 bits to download Oracle.DataAccess.dll .

Is this even the right library?

thanks

EDIT

tnsnames.ora file as follows:

 # tnsnames.ora Network Configuration File: C:\app\UserName\product\11.2.0\dbhome_3\network\admin\tnsnames.ora # Generated by Oracle configuration tools. ORAC = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orac.example.com) ) ) LISTENER_ORAC = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522)) 

UPDATE

I tried to connect using the Oracle Sql developer. This works as long as I use the TNS connection type, but it does not work if I use the basic connection type.

I also noticed that in my services there are 2 names

OracleOraDb11g_home1TNSListener OracleOraDb11g_home2TNSListener

Orac dbhome is home3 I think this could be a problem? If so does anyone know how I can fix this?

thanks

UPDATE HKEY_LOCAL_MACHINE \ SOFTWARE \ ORACLE \ has two properties (default) and inst_loc. There are several folders, two of which are called "KEY_OraDb11g_home1" and "KEY_OraDb11g_home2", both of which contain the ORACLE_HOME property, which they:

KEY_OraDb11g_home1 - ORACLE_HOME = C: \ app \ UserName \ product \ 11.2.0 \ dbhome_2 KEY_OraDb11g_home2 - ORACLE_HOME = C: \ app \ UserName \ product \ 11.2.0 \ dbhome_3

The SID for Db in home1 is something called OracleDev, maybe I installed it at some point a long time ago, but I certainly donโ€™t need it now if it causes a problem

thanks

+8
c # sql oracle
source share
4 answers

EDIT

Try something else.

Perhaps ODP.NET does not know where to find your Oracle Home because it is not defined in the PATH environment variable or if it is not installed in the registry.

Check your PATH and make sure it contains your Oracle Home directory and "Oracle Home \ bin". For the registry, find HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\ . It should have a key named HOME0 with the string value ORACLE_HOME . Make sure it points to your Oracle Home.

+2
source share

Check the host file in the folder C: \ windows \ system32 \ drivers \ etc, especially if the machine is a virtual machine and the IP address of the local host can change if the IP address of the virtual machine is not static. If necessary, change the IP of the local host to this file

0
source share

There was a similar problem:
Visual Studio used the wrong version of tnsnames.ora in .. \ 11.2.0 \ client_1 \ network \ admin
TNS Ping used the correct version of tnsnames.ora in .. \ 11.2.0 \ client_2 \ network \ admin

Therefore, tnsping was successful, but Visual Studio returned: ORA-12545: Connection failed because the target host or object does not exist.

The solution, perhaps not the best, copied the correct version of tnsnames.ora in .. \ 11.2.0 \ client_1 \ network \ admin

0
source share

I don't know why, but setting the HOST to 0.0.0.0 in tnsnames.ora and listner.ora worked for me.

Of course I had to start lsnrctl start

0
source share

All Articles