Search code examples
c#oracle-databaseoracle-manageddataaccess

Oracle.ManagedDataAccess TNS_ADMIN in Web.Config


I am trying to configure my solution that is using the Oracle.ManagedDataAccess library to use TNS names in the connection strings instead of explicit data sources. Before any changes the program is working correctly, but all of my attempts to configured the TNS settings have failed.

I have my TNS file locally on my computer for development at C:\oracle\tns\tnsnames.ora.

I've updated my connection string in the web.config to use the alias present in my TNS file:

<connectionStrings>
  <add name="OracleConnectionString"
      connectionString="Data Source=DEV1;Persist Security Info=True;User ID=myUser;Password=myPassword;"
      providerName="System.Data.OracleClient"/>
</connectionStrings>

The configSection has also been added as well as the configuration for the library:

<configuration>
  <configSections>
    <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
  </configSections>
  ....
  <oracle.manageddataaccess.client>
    <version number="*">
      <settings>
        <setting name="TNS_ADMIN" value="C:\oracle\TNS\tnsnames.ora" />
      </settings>
    </version>
  </oracle.manageddataaccess.client>
</configuration>

When I try running the program though I get the error ORA-12154: TNS:could not resolve the connect identifier specified. I'm not sure what I am configuring incorrectly as it does not give much information.

One thing to note is that the solution consists of an MVC project with the web.config and a class library that handles the database access. The reference to Oracle.ManagedDataAccess is in the class library. I have tried putting the Oracle configuration section (and its configSection) in the web.config, the app.config, and both but none of those setups worked.


Solution

  • first, you configuration for managed oracle should be in your entry project's config files. In your case , I guess it's should be in "web.config"

    second , your TNS_ADMIN should be a folder , not a file, Like following

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