Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OracleConnection.Open is throwing ORA-12541 TNS no listener

So I am connecting to an external server through C#. I just installed Oracle 11g client on my machine from here: http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html (255MB one).

After reading many blogs/questions I found this article to be useful:

http://dbaspot.com/oracle-faq/444787-ora-12541-tns-no-listener.html

So is this correct? I cannot do anything. The DBA has to edit the LISTENER.ORA file?

My tnsnames.ora looks like this:

  TestingConnect=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = TestHostName.us.local)(PORT = 1523))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = TEST)
    )
  )

It is throwing me the err at:

Oracle.DataAccess.Client.OracleConnection connection = new Oracle.DataAccess.Client.OracleConnection();

connection.ConnectionString = "Data Source=TestHostName.us.local;Persist Security Info=True;" + "User ID=tesName;Password=test";

connection.Open() //Throwing ERR!!!

What should I do? I appreciate any comments. Thanks!

like image 736
RG-3 Avatar asked Sep 24 '12 19:09

RG-3


People also ask

How do I fix ORA-12541 TNS no listener?

First, make sure that the listener is up and running. To do this, go to the Control Panel into Services under NT or listener control program (LSNRCTL). If the listener is up and running, the problem may lie with the listener not having been associated with the correct instance or protocol.

What does TNS no listener mean?

ORA-12541: TNS:no listener. Cause: The connection request could not be completed because the listener is not running. Action: Ensure that the supplied destination address matches one of the addresses used by the listener - compare the TNSNAMES.

What is Oracle listener error?

An ORA-12541 error occurs when the listener for the destination server is down or unreachable. This can be due to the listener not being started or being incorrectly configured, or it can be due to a network connection problem.


2 Answers

You can do this a couple of ways: Using your TNSNames file the data source should specify the TNSHosts entry name (the bit before the first "=" from the tnsnames.ora), not the host name:

connection.ConnectionString = "Data Source=TestingConnect;Persist Security Info=True;" + "User ID=tesName;Password=test"; 

Or you can put the entire TNS entry in the connection string like so:

connection.ConnectionString = "Data Source=(DESCRIPTION = " +
    "(ADDRESS = (PROTOCOL = TCP)(HOST = TestHostName.us.local)(PORT = 1523))" +
    "(CONNECT_DATA =" + 
    "(SERVER = DEDICATED)" + 
    "(SERVICE_NAME = TEST))" + 
    ");Persist Security Info=True;User ID=tesName;Password=test"; 
like image 76
dkackman Avatar answered Oct 13 '22 01:10

dkackman


Thanks for all your input. I changed my connection string and it worked. Here its what looks like:

 private static string GetConnectionString()
    {
        return "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=TestHostName.us.local)(PORT=1523) ) )" +
               "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=CCDB)));User id=UserName; Password=Password; enlist=false; pooling=false;";
    }
like image 32
RG-3 Avatar answered Oct 13 '22 02:10

RG-3