1
votes

I want to connect to Oracle database from C# but I can't Because this errors that ORA-12545: Connect failed because target host or object does not exist so how can i ?

C# code

  string strConn = "Data Source =(DESCRIPTION =" +
                                 "(ADDRESS = (PROTOCOL = TCP)(HOST = DESKTOP-EIQ5MRF)(PORT = 1521))" +
                                 "(CONNECT_DATA =" +
                                 " (SERVER = DEDICATED)" +
                                 "(SERVICE_NAME = XE)" +
                                 ")" +
                                 ");User Id =system;password=bluesky;";
                OracleConnection conn = new OracleConnection(strConn);

                conn.Open();
                conn.Close();

listener.ora

SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server) (PROGRAM = extproc) ) (SID_DESC = (SID_NAME = CLRExtProc) (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server) (PROGRAM = extproc) ) )

LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) (ADDRESS = (PROTOCOL = TCP)(HOST = DESKTOP-EIQ5MRF)(PORT = 1521)) ) )

DEFAULT_SERVICE_LISTENER = (XE)

tnsnames.ora

XE = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = DESKTOP-EIQ5MRF)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE) ) )

EXTPROC_CONNECTION_DATA = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) ) (CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO) ) )

ORACLR_CONNECTION_DATA = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) ) (CONNECT_DATA = (SID = CLRExtProc) (PRESENTATION = RO) ) )

1
Check your connection string. The most likely cause is that you have made a mistake in there.Takarii
"ORA-12454: connect failed because target host or object does not exist "-check your connection stringM. Wiśnicki
Just a suggestion,try to replace DESKTOP-EIQ5MRF with the machine ip.Hameed Syed

1 Answers

1
votes

The error

ORA-12454: connect failed because target host or object does not exist

It's mean you have problem with connection string, check all access data, machine name once again and try use this connection string, you forgot add "ADDRESS_LIST" , check doc. here.

Using ODP.NET without tnsnames.ora, should be like

    var sampleConn= @"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=    (PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))
                    (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));
                     User Id=myUsername;Password=myPassword;"

So you connection string should look like

   string strCon =@"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=DESKTOP-EIQ5MRF)(PORT=1521)))
                             (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XE)));
                             User Id = system; Password = bluesky; ";