1

I have built a small WinForms application and am using the ODP.NET Managed Driver to connect to an Oracle database. I have followed the instructions in this document to set up the connection using the application.config file:

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/12c/r1/appdev/dotnet/Web_version_Fully_Managed_ODPnet_OBE/odpnetmngdrv.html

Based on documentation I found in several places I was under the impression that the application.config file has the highest priority with respect to the database alias resolution. Eg: https://docs.oracle.com/cd/E48297_01/doc/win.121/e41125/featConfig.htm#autoId6

However what I am experiencing is that if the TNS_ADMIN environment variable exists it has a higher priority than the data source alias in the 'dataSources' section in the .NET config file. I know that the TNS_ADMIN setting is one option for configuring the connection but I have not configured this setting in my application.config file.

The last 2 posts in this thread seem to be referring to the same issue that I am experiencing. https://community.oracle.com/message/10610812#10610812

The last post claims that the issue would be due to TNS_ADMIN being defined in machine.config settings and that this overrides everything else. However this contradicts the documentation here: https://docs.oracle.com/cd/E48297_01/doc/win.121/e41125/featConfig.htm#autoId4

I also tried searching all 4 of my machine.config files and was unable to find any references to TNS_ADMIN. So while in my case TNS_ADMIN location is definitely being prioritized I am unable to find a reference to the TNS_ADMIN variable.

Is the official precedence order that I posted in the second link above accurate? What about the machine.config? Where should I be looking for references to the TNS_ADMIN variable?

1
  • Just as this answer didn't answer the original question, it may also help here without actually answering your question. You don't have to figure out which TNS_ADMIN is taking precedence if you just define the full connection in your .config file. Also no longer need to verify all machines have Oracle exactly the same everywhere. I found this has saved me ton of time vs fighting Oracle.
    – jozolo
    Commented Jul 30, 2018 at 21:12

1 Answer 1

1

This seems to be a difficult topic. Download the Process Monitor from Microsoft Sysinternals and have a look which files are loaded in which order.

I think the precedence order depends on the release and definitely the documentation seems to be wrong.

In Oracle Data Provider for .NET Developer's Guide nothing in mentioned about TNS_ADMIN environment variable, however when you check with Process Monitor then you see it is taken (as far as I remember even with highest precedence)

When you install latest version 12.2 of ODP.NET Managed Driver then you get entry in Registry at HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\ODP.NET.Managed\4.122.1.0\TNS_ADMIN despite documentation says Registry is not used.

So my recommendation is: Set all possible values to the same folder, create even a symbolic link at %ORACLE_HOME%\network\admin pointing to location of tnsnames.ora.

See also Determining location of relevant tnsnames.ora file

1
  • 1
    According to the process monitor first it accesses the app.config file in the same directory as the exe. Then goes on to look for a tnsnames.ora in the exe folder and finally in the folder referenced by the TNS_ADMIN environment variable. If it doesn't find the files in the last 2 locations it falls back on the value in the dataSource section in the config file. I'm sure it's accessing the config file first because it needs other information but it does not use the dataSource right away. Thanks for the process monitor suggestion.
    – NenadK
    Commented Jul 10, 2018 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.