ORA-12545: Connect failed because target host or object does not exist - No error on System.Data.OracleClient

Can't believe I am having to ask this question, but I cannot for the life of me connect to an Oracle 11g database.

The following works while using System.Data.OracleClient - but obviously this is depreciated. When using the exact 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]);
            }
        }

Could anyone help me out with what I am doing wrong?

I had to change the program to be 32 bit for the Oracle.DataAccess.dll to load.

Is this even the correct library to be using???

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 have tried connecting using Oracle Sql developer. This works so long as I use the TNS connection type, but doesn't work if I use the Basic connection type.

Also I've noticed that in my services there are 2 called

OracleOraDb11g_home1TNSListener OracleOraDb11g_home2TNSListener

The orac dbhome is home3 I believe, could this be the issue?? If so does anyone know how I would go about fixing it?

Thanks

UPDATE In HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\ there are two properties (Default) and inst_loc. There are a few folders two of which are called "KEY_OraDb11g_home1" and "KEY_OraDb11g_home2" these both contain a property called ORACLE_HOME they are:

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 the Db in home1 is something called OracleDev, I may have installed this at some point long ago, but I certainly don't need it now if it is causing a problem

Thanks

Answers


EDIT

Let's try something else.

It's possible that ODP.NET doesn't know where to find your Oracle Home because it is not defined in your PATH environment variable, or if it is not set in the registry.

Check your PATH and make sure it contains your Oracle Home directory, and "Oracle Home\bin". For the registry, look for HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\. In it there should be a key called HOME0 with a string value of ORACLE_HOME. Make sure it points to your Oracle Home.


Check the host file, under C:\windows\system32\drivers\etc, especially if the machine is VM and the IP address of local host might change,if IP address of VM is not static. Change the IP of local host on that file if necessary


Had a similar issue: 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

Hence tnsping was successful but Visual Studio returned: ORA-12545: Connect failed because target host or object does not exist.

Solution, probably not the best one, copied the correct version of tnsnames.ora to ..\11.2.0\client_1\network\admin


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

Of course, had to run lsnrctl start


Need Your Help

not able to connect bluetooth devices

android eclipse bluetooth device connectivity

i successfully enabled bluetooth and displayed the list of nearby devices but app closes whenever i click on the device displayed in list. not able to figure out what the problem, it would be really

Can I set to ScrollBar a floating Step?

.net winforms scrollbar

I have a panel in witch I represent a timeline - 24 hours(24 x 60 min = 1 440 min).