0

The following Database connection code is working in one project but not for other.

Both

  1. Reside in the same folder
  2. Accessing the same Oracle.dataaccess dll

I am unable to understand what might have led the other project not connect to oracle DB.

I am out of ideas on how to make this project use the connection strings in the tnsnames.ora.

Any help is appreciated

Code:

string constr = "Data Source=Dev11G;User Id=Username;Password=pwd;";
OracleConnection con = new OracleConnection(constr);
con.Open();
OracleCommand cmd = new OracleCommand("Select * from Table", con);
cmd.CommandType = CommandType.Text;
DataTable dt = new DataTable();
using (OracleDataAdapter da = new OracleDataAdapter())
{
     da.SelectCommand = cmd;
     da.Fill(dt);
}

Error being Recieved: ORA-12154:TNS:could not resolve the connect identifier specified
Error occuring at: con.Open();

Matthijs
  • 3,162
  • 4
  • 25
  • 46

2 Answers2

0

Have you tried using EZCONNECT instead of using TNS Names? TNS Names is convenient on a client (with IDEs, etc), but any time you have to deploy an application, you're dependent on whomever maintains that machine. If they update TNS names, it could potentially interfere with your application.

The connection string can be as simple as:

string conString = String.Format("Direct=true;Data Source={0};Port={1};" +
    "Service Name={2};User={3};Password={4};Connection Timeout={5}", ...

If you don't know these values, you can find a machine where it's set up correctly and:

tnsping Dev11G
Hambone
  • 15,600
  • 8
  • 46
  • 69
0

Thanks for all of your posts.I finally found it.it has to do with the local IIS server settings.The project that is succesfully connecting to Oracle is using visual studio development server...while the other one which is unable to connect is using local IIS server.So I have to grant the IIS access to the tnsnames.ora folder.

This post really helped me...
Oracle ORA-12154 error on local IIS, but not with Visual Studio Development Server

Community
  • 1
  • 1