0

I am trying to configure my solution that is using the Oracle.ManagedDataAccess library to use TNS names as follows:

<oracle.manageddataaccess.client>
    <version number="*">
      <settings>
        <setting name="TNS_ADMIN" value="C:\oracle\TNS" /> 
      </settings>
    </version>
  </oracle.manageddataaccess.client>
</configuration>

It is possible to set the TNS_ADMIN path value from the environment variables at runtime by code?

Thanks.

2 Answers2

0

We did something similar to your problem. Here is my solution:

 internal static OracleDatabase ServerConnection()
        {
            try
            {
                string connectionString = TNSORA.TnsNames();

                OracleConnection connection = new OracleConnection(connectionString);
                OracleDatabase oracleDatabase = new OracleDatabase(connection);
                return oracleDatabase;
            }
            catch {return null;}

        }

internal static string TnsNames()
        {
//TODO get your TNS from your environment variable, if you have more you have to select by code which is the correct one
        }
KnApP993
  • 66
  • 2
  • 9
0

Simply remove the setting from the .NET config file. The ODP.NET Managed driver will automatically use the current value from TNS_ADMIN environment setting.

Note, this is in contradiction to the Oracle documentation but it works anyway. See also Determining location of relevant tnsnames.ora file

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110