Unable to connect through ODP Managed driver

805 views Asked by At

I have a windows forms app, in which I am trying to connect to Oracle 11g DB with OracleManaged driver, which ends with an exception "ORA-12154: TNS:could not resolve the connect identifier specified". However when I am trying to connect through ODP.NET 64bit dlls, it is connecting (for this I ensured building the app in x64). The sample code below. If I toggle to second statement, I am getting the error while opening the connection.

Oracle.DataAccess.Client.OracleConnection con = new Oracle.DataAccess.Client.OracleConnection();
//Oracle.ManagedDataAccess.Client.OracleConnection con = new Oracle.ManagedDataAccess.Client.OracleConnection();
con.ConnectionString = "Data Source=v3;User Id=xxx;Password=xxx;";
con.Open();
MessageBox.Show("Done");
con.Close();

Is there a setting I am missing? Even I tried with the configure.bat that came along with manaed ODP (64bit)

2

There are 2 answers

1
Krishna Sarma On

I got this worked by copying the tnsnames.ora file to bin folder. It seems like the managed driver couldn't find the right tnsname.ora file.

0
MensSana On

The reason is simple, your managed driver does not know where to find the TNSNAMES.ORA. Oracle says it depends on environment variables. What we do here is to set TNS_ADMIN environment variable to the folder containing the TNSNAMES and everything works perfectly. This is the best solution since it allows you not having multiple instances of TNSNAMES.ora on your station...