this is error ORA-12154: TNS:could not resolve the connect identifier specified?

محمد النعيمي picture محمد النعيمي · Dec 3, 2013 · Viewed 164.2k times · Source

I've this code :

OracleConnection con = new OracleConnection("data source=localhost;user id=fastecit;password=fastecit"); 
con.Open(); string sql="Select userId from tblusers";    
OracleCommand cmd = new OracleCommand(sql, con);
OracleDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{ messageBox.Show(dr[0].Tostring()); } 

Same code in both projects,

in project1 "WinForm" Is Working correctly

in project2 "Excel 2007 addins" Following error appears:

ORA-12154: TNS:could not resolve the connect identifier specified

I'm using C#.net 2010 ,office 2007 , windows8, oracle 10g.

When preparing a manual connection to the database, as shown in the picture

Visual Studio, open View menu + Server Explorer.

Right mouse click on Data Connection + Add Connection + Select Oracle Database server Name : localhost or name of my machine, set username & password and click on Test Connection, test is no succeeds.enter image description here

Answer

LALBABU picture LALBABU · Nov 7, 2014

ORA-12154: TNS:could not resolve the connect identifier specified?

In case the TNS is not defined you can also try this one:

If you are using C#.net 2010 or other version of VS and oracle 10g express edition or lower version, and you make a connection string like this:

static string constr = @"Data Source=(DESCRIPTION=
    (ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=yourhostname )(PORT=1521)))
    (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XE)));
    User Id=system ;Password=yourpasswrd"; 

After that you get error message ORA-12154: TNS:could not resolve the connect identifier specified then first you have to do restart your system and run your project.

And if Your windows is 64 bit then you need to install oracle 11g 32 bit and if you installed 11g 64 bit then you need to Install Oracle 11g Oracle Data Access Components (ODAC) with Oracle Developer Tools for Visual Studio version 11.2.0.1.2 or later from OTN and check it in Oracle Universal Installer Please be sure that the following are checked:

Oracle Data Provider for .NET 2.0

Oracle Providers for ASP.NET

Oracle Developer Tools for Visual Studio

Oracle Instant Client 

And then restart your Visual Studio and then run your project .... NOTE:- SYSTEM RESTART IS necessary TO SOLVE THIS TYPES OF ERROR.......