使用托管的ODP.NET时,如何从C#查询LDAP来解析Oracle TNS主机名? [英] How do I query LDAP from C# to resolve Oracle TNS hostname while using managed ODP.NET?

查看:157
本文介绍了使用托管的ODP.NET时,如何从C#查询LDAP来解析Oracle TNS主机名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

进一步了解我之前的问题,我设法通过

Further to my previous Question, which I managed to answer myself with help from the Oracle forums, I now have another issue which follows on from the earlier one (provided for background).

我希望直接从我的C#代码中查询LDAP,以执行Oracle TNS主机名的LDAP查找,以获取连接字符串.通常将其存储在 tnsnames.ora 中,并且我的组织使用LDAP(通过 ldap.ora )来使用Active Directory解析LDAP服务器中的主机名.

I wish to query LDAP directly from my C# code to perform an LDAP lookup of an Oracle TNS hostname in order to get the connection string. This is normally stored in tnsnames.ora, and my organisation uses LDAP (via ldap.ora) to resolve hostnames from an LDAP server using Active Directory.

但是,我正在使用 ODP.NET,托管驱动程序测试版( Oracle.ManagedDataAccess.dll )在我的C#应用​​程序中,该应用程序不支持

However, I am using ODP.NET, Managed Driver Beta (Oracle.ManagedDataAccess.dll) in my C# application which doesn't support LDAP as mentioned in the release notes pointed to by the Oracle forum reply I mentioned earlier. This is why I wish to query LDAP directly from C#.

我找到了一种方法,在这里使用DirectoryEntryDirectorySearcher,但是我不知道该放什么作为DirectorySearcher的参数.我可以使用以下格式的 ldap.ora :

I found a way to do this here using DirectoryEntry and DirectorySearcher, but I have no idea what to put as the parameters to DirectorySearcher. I have access to ldap.ora which is in the following format:

#LDAP.ORA配置
#由Oracle配置工具生成.
DEFAULT_ADMIN_CONTEXT ="dc = xx,dc = mycompany,dc = com"
DIRECTORY_SERVERS =(ldap_server1.mycompany.com:389:636,ldap_server2.mycompany.com:389:636,...)DIRECTORY_SERVER_TYPE = OID

# LDAP.ORA Configuration
# Generated by Oracle configuration tools.
DEFAULT_ADMIN_CONTEXT = "dc=xx,dc=mycompany,dc=com"
DIRECTORY_SERVERS = (ldap_server1.mycompany.com:389:636,ldap_server2.mycompany.com:389:636, ...) DIRECTORY_SERVER_TYPE = OID

但是,如何将其映射到在C#代码中设置LDAP查询?

But, how do I map this to setting up the LDAP query in my C# code?

推荐答案

从我在使用OpenLDAP的Oracle数据库名称解析,代码应如下所示:

Judging by what I found in Oracle Database Name Resolution with OpenLDAP, the code should look something like this:

string directoryServer = "ldap_server1.mycompany.com:389";
string defaultAdminContext = "dc=xx,dc=mycompany,dc=com";
string oracleHostEntryPath = string.Format("LDAP://{0}/cn=OracleContext,{1}", directoryServer, defaultAdminContext);

var directoryEntry = new DirectoryEntry(oracleHostEntryPath) {AuthenticationType = AuthenticationTypes.None};
var directorySearcher = new DirectorySearcher(directoryEntry, "(&(objectclass=orclNetService)(cn=ABCDEFG1))", new[] { "orclnetdescstring" }, SearchScope.Subtree);

string oracleNetDescription = Encoding.Default.GetString(des.FindOne().Properties["orclnetdescstring"][0] as byte[]);

这篇关于使用托管的ODP.NET时,如何从C#查询LDAP来解析Oracle TNS主机名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆