1

I've inherited an app that uses NHibernate and FluentNibernate to connect to an Oracle database. Unfortunately, I have no experience with NHibernate. The current connection string is like so:

Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=0000)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=servicename)));User Id={username};Password={password};

but now needs to switch over to LDAP (see the last code snippet).

My question, is it possible to make a change only to the web.config with an LDAP connection or will I need to add the Oracle.ManagedDataAccess and make some code changes?

It is my understanding that OracleClientConfiguration has been deprecated based on this page hence the part of the question about a new nuget package. Another note, there isn't a hibernate.cfg.xml file within the project (which I think is ok?) but wondering if this project isn't using the best practices for NHibernate. Any other hints or tips would be appreciated.

C# code:

private ISessionFactory GetSessionFactory()
{
      var connectionString = LoginHelper.GetConnectionString(ConnectionStringSetting, LoginInfoSetting);

      var iSessionFactory
         = Fluently
            .Configure()
            .Database(OracleClientConfiguration.Oracle10.ConnectionString(connectionString))
            .Mappings(e => e.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
            .BuildSessionFactory();

      return iSessionFactory;
}

Web.config (there no other references to NHibernate in the Web.config. There are some references to dependentAssembly in other dll.config files):

<configuration>
   <configSections>
      <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
   <configSections>
<configuration>

What I (think I) need in the Web.config is something like so:

<oracle.dataaccess.client> <!-- or <oracle.manageddataaccess.client>? -->
  <version number="*">
      <LDAPsettings>
         <LDAPsetting name="DIRECTORY_SERVERS" value="" />
         <LDAPsetting name="DIRECTORY_SERVER_TYPE" value="" />
         <LDAPsetting name="DEFAULT_ADMIN_CONTEXT" value="" />
      </LDAPsettings>
      <settings>
         <setting name="NAMES.DIRECTORY_PATH" value="" />
         <setting name="LDAP_ADMIN" value="" />
      </settings>
   </version>
</oracle.dataaccess.client> 

EDIT 1: Contents of ldap.ora file:

DIRECTORY_SERVERS=(ldap:XXX)
DEFAULT_ADMIN_CONTEXT="dc=Oracle,dc=com"
DIRECTORY_SERVER_TYPE=ad
user94614
  • 511
  • 3
  • 6
  • 26

2 Answers2

1

Here is what I did in order to get this to work...

In the Oracle folder structure, navigate to the Network folder.

Add the following files (should be able to copy and paste another folder down called Sample):

  • sqlnet.ora
  • ldap.ora
  • tnsnames.ora

sqlnet.ora (the key here was adding LDAP to the beginning of the list):

SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (LDAP, TNSNAMES, EZCONNECT)

ldap.ora:

DIRECTORY_SERVERS=(ldap:XXX:XXX)
DEFAULT_ADMIN_CONTEXT="dc=oracle,dc=com"
DIRECTORY_SERVER_TYPE=XX

tnsnames.ora:

No change was required; left as default

Connection string:

<add name="connection" connectionString="Data Source=YourDataSource"/>
<!-- might need to add a username/password -->
user94614
  • 511
  • 3
  • 6
  • 26
0

According documentation it should be this:

<LDAPsettings>
  <LDAPsetting name="DIRECTORY_TYPE" value="AD" />
  <LDAPsetting name="DEFAULT_ADMIN_CONTEXT" value="dc=Oracle,dc=com"/>
</LDAPsettings>

Or use

<settings>
  <setting name="TNS_ADMIN" value="C:\oracle\work"/>
</settings>

and specify LDAP settings in C:\oracle\work\ldap.ora file (in conjunction with C:\oracle\work\sqlnet.ora file).

I don't think it is still valid but have a look at ODP.NET Managed library does resolve alias, but 32-bit library does

You can modify the config file with a simple text editor or use the config tool OraProvCfg.exe. Would be like this:

OraProvCfg.exe /action:config /product:odpm /frameworkversion:v4.0.30319 /providerpath:C:\oracle\product\12.1\Client_x64\odp.net\managed\common\Oracle.ManagedDataAccess.dll /set:settings\TNS_ADMIN:C:\oracle\network\admin

OraProvCfg.exe /action:config /product:odpm /frameworkversion:v4.0.30319 /providerpath:C:\oracle\product\12.1\Client_x64\odp.net\managed\common\Oracle.ManagedDataAccess.dll /set:LDAPsettings\DIRECTORY_TYPE:ad

Note, you have a OraProvCfg.exe for 32-bit (x86) and for 64-bit. Run the one which matches to your application, (or simply run both).

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
  • Thanks for your response. Are you saying it's an either or and not both on the settings? I also don't have an sqlnet.ora file only a ldap.ora file. I don't have a reference to any Oracle DataAccess dll so there isn't a I can place those settings in. Any thoughts on that? I'm a little leery changing something I don't quite understand but maybe I do need to rework might of this app. – user94614 Apr 16 '21 at 15:02
  • It's an "or". Either put all information into the web.config file, or provide location of `sqlnet.ora` and `ldap.ora` file by `TNS_ADMIN` value and put all information in these files. – Wernfried Domscheit Apr 16 '21 at 15:12
  • The [default](https://docs.oracle.com/database/121/NETRF/sqlnet.htm#NETRF192) is `NAMES.DIRECTORY_PATH=(tnsnames, ldap, ezconnect)`, so it should work even without any `sqlnet.ora` file, because the default covers LDAP resolution. – Wernfried Domscheit Apr 16 '21 at 15:16
  • I didn't forget about you...the documentation also states that the LDAPsettings must be inside a tag which is inside a . Unfortunately, I don't have either. WIth those config values, I get a: *The configuration section 'LDAPSettings' cannot be read because it is missing a section declaration*. Do you know of a way I can get the additional configuration added? my effots have not been successful (so far) – user94614 Apr 26 '21 at 20:59
  • It's a simple text file, should be no problem to edit it. In your Oracle folder you may also have a config-tool `OraProvCfg.exe`. See my update. – Wernfried Domscheit Apr 27 '21 at 06:42