title: ORA-12545: Connect failed because target host or object does not exist - No error on System.Data.OracleClient
body: <p>Can't believe I am having to ask this question, but I cannot for the life of me connect to an Oracle 11g database.</p>
  
  <p>The following works while using <code>System.Data.OracleClient</code> - but obviously this is depreciated.
  When using the exact same code but using <code>Oracle.DataAccess.OracleClient</code> I get the following error</p>
  
  <pre><code>{"ORA-12545: Connect failed because target host or object does not exist"}
  </code></pre>
  
  <p>Here is my code</p>
  
  <pre><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]);
              }
          }
  </code></pre>
  
  <p>Could anyone help me out with what I am doing wrong?</p>
  
  <p>I had to change the program to be 32 bit for the <code>Oracle.DataAccess.dll</code> to load.</p>
  
  <p>Is this even the correct library to be using???</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>tnsnames.ora file as follows:</p>
  
  <pre><code># 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))
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>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.</p>
  
  <p>Also I've noticed that in my services there are 2 called </p>
  
  <p>OracleOraDb11g_home1TNSListener
  OracleOraDb11g_home2TNSListener</p>
  
  <p>The orac dbhome is home3 I believe, could this be the issue??
  If so does anyone know how I would go about fixing it?</p>
  
  <p>Thanks</p>
  
  <p><strong>UPDATE</strong>
  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:</p>
  
  <p>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</p>
  
  <p>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</p>
  
  <p>Thanks</p>