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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With