• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7806
  • Last Modified:

ORA 12154 : TNS : could not resolve the connect identifier specified( error in C# code)

Hi, I am trying to connect to oracle database 10 g using visual C# 2005. I am using ODP.Net for connecting to the database. I have configured .Net Configuration Assistant in the Programs->Oracle-OraDb10g_home1->Configuration and Migration Tools ->.Net Configuration Assistant.  I have installed ODP.Net on my machine.  I have referenced Oracle.DataAccess.dll (under dir client1) in the program ( in solution explorer ->add reference).Below is my code:
using System;
using System.Collections.Generic;
using System.Text;
using Oracle.DataAccess.Client;
namespace VamConnect
    class Program
        static void Main(string[] args)
            string constr = "User Id=SYSTEM;Password=mskiranavk;Data Source=orcl";
            OracleConnection con = new OracleConnection(constr);
            Console.WriteLine("Connected to Oracle" + con.ServerVersion);
When I try to run these code I am getting an unhandled exception :ORA 12154 : TNS : could not resolve the connect identifier specified. I have tried to change the tnsnames.ora and listener.ora , however could not connect. Anyone please help me with this code. Its urgent...
thanks in advance
3 Solutions
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>I have tried to change the tnsnames.ora and listener.ora
can you post the content of tnsnames.ora (and sqlnet.ora)
vamshiav1Author Commented:
hi angel thanks for the response:
The contents of TNSNAMES.ORA:

# tnsnames.ora Network Configuration File: C:\oracle\product\10.2.0\db_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.

      (ADDRESS = (PROTOCOL = TCP)(HOST = = 1521))
      (SERVICE_NAME = orcl)

      (SID = PLSExtProc)

# listener.ora Network Configuration File: C:\oracle\product\10.2.0\db_1\network\admin\listener.ora
# Generated by Oracle configuration tools.

    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = C:\oracle\product\10.2.0\db_1)
      (PROGRAM = extproc)


      (ADDRESS = (PROTOCOL = TCP)(HOST = ITSPH316_5.aamu.edu)(PORT = 1521))
open your TNSNAMES.ORA file and search for orcl.

If you dont get it, you've already made a mistake. Try adding it and try your pgm again.

If you've orcl and you'r not able to connect,

open your SQLNET.ORA and there should be a default domain property. Take the value from there and append it with your orcl. For ex if you've that value as yourcompany.com then your host string will become orcl.yourcompany.com

Try this instead of orcl in your pgm and check what happens.

If that also does not work, try doing a tnsping to orcl.
Open command prompt (click start->run->type cmd) and type tnsping orcl

If that doesnt reach the server, check again the tnsnames.ora the ip address and the port and service id and ensure whether all are correct or not.

If all the things are there in place but still not working,

how many oracle homes do you have?


see how many are being displayed in combo. If more than 1 then select the appropirate one on which you'r modifying the tnsnames.ora

If only one is displayed did you do any uninstallation or installation recently? did you clear up registry entries? open regedit (start->run->type regedit) Go to HKEY_LOCAL_MACHINE->softwares->Oracle->All_homes delete the ones that were removed already.

You must be all set to work, if not post here again. We will see.
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

vamshiav1Author Commented:
Here are the contents of sqlnet.ora:
# sqlnet.ora Network Configuration File: C:\oracle\product\10.2.0\db_1\network\admin\sqlnet.ora
# Generated by Oracle configuration tools.

# This file is actually generated by netca. But if customers choose to
# install "Software Only", this file wont exist and without the native
# authentication, they will not be able to connect to the database on NT.


Check oracle homes as I said. Your tnsnames/sqlnet seems ok.

I think you've installed oracle in your machine, isnt it? Did you try connecting it from sqlplus, whats the response?
vamshiav1Author Commented:
I have installed oracle 10 g on my system. I have only one instance "orcl" installed on the machine. and from
SQL , I could connect using the below code.
SQL> connect SYSTEM/mskiranavk@orcl
let me try your solution and I will let you know.. thank you for replies ram...
did u try tnsping from ur dos prompt

check this, it might be possible that ur path for Oracle & Windows having issues

and if still doesnt work then try this

start > programs > ... > Net Configuration Assistant

here u should able to add & test your listeners

hope this assists!
vamshiav1Author Commented:
I have created another SID orclvam on my system.ram I have checked all these steps . Program is not working...
thank you..
Cause: A connection to a database or other service was requested using a connect identifier, and the connect identifier specified could not be resolved into a connect descriptor using one of the naming methods configured. For example, if the type of connect identifier used was a net service name then the net service name could not be found in a naming method repository, or the repository could not be located or reached.

Action: - If you are using local naming (TNSNAMES.ORA file):- Make sure that &quo;TNSNAMES&quo; is listed as one of the values of the NAMES.DIRECTORY_PATH parameter in the Oracle Net profile (SQLNET.ORA)- Verify that a TNSNAMES.ORA file exists and is in the proper directory and is accessible.- Check that the net service name used as the connect identifier exists in the TNSNAMES.ORA file.- Make sure there are no syntax errors anywhere in the TNSNAMES.ORA file. Look for unmatched parentheses or stray characters. Errors in a TNSNAMES.ORA file may make it unusable.- If you are using directory naming:- Verify that &quo;LDAP&quo; is listed as one of the values of the NAMES.DIRETORY_PATH parameter in the Oracle Net profile (SQLNET.ORA).- Verify that the LDAP directory server is up and that it is accessible.- Verify that the net service name or database name used as the connect identifier is configured in the directory.- Verify that the default context being used is correct by specifying a fully qualified net service name or a full LDAP DN as the connect identifier- If you are using easy connect naming:- Verify that &quo;EZCONNECT&quo; is listed as one of the values of the NAMES.DIRETORY_PATH parameter in the Oracle Net profile (SQLNET.ORA).- Make sure the host, port and service name specified are correct.- Try enclosing the connect identifier in quote marks. See the Oracle Net Services Administrators Guide or the Oracle operating system specific guide for more information on naming.

Few things to try.
1. Check for the Windows Service "OracleServiceSID" and start it if its not already started. Also make it AUTOMATIC.
2. Check the entry for SQLNET.AUTHENTICATION_SERVICE in SQLNET.ORA file under OracleHome\Network\Admin and set its value to NTS.
3. Check the Windows Service "OracleListenerxx" and start it if its not already started.
4. Check for TNSNAMES.ORA under OracleHome\Network\Admin and confirm that it contains a valid ConnectString for your instance.
5. Goto Command prompt and type this
c:\sqlplus "/ as sysdba"
If you see the result as "Connected to an Idle Instance" then type STARTUP

Chetan Sachdeva
vamshiav1Author Commented:
hi folks I got my program working... this was my problem:

In Visual C# 2005, when you try to connect to the oracle database10 g using ODP.Net, if you get
the following error(after installing ODP.Net and configuring Net Configuration assistant)...

Error ORA 12154 TNS: could not resolve the identifier name specified:

Try the below solution:

The three files in the SQLNET.ORA , LISTENER.ORA, TNSNAMES.ORA in the
oracle database side should also be present in the client side after
installating it.

To say in exact terms:
The three files(same files) in
dir(C:\oracle\product\10.2.0\db_1\NETWORK\ADMIN) should also be present in the

If not present just copy and past the three files in client side and try to run the c# code.
That shuuld solve the problem.


Thank you for responses.. my program is working

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now