Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Further to my second comment in the <a href="https://stackoverflow.com/a/14569342/197591">accepted Answer</a>, this is the code for performing an LDAP lookup which improves the original version I found <a href="http://www.codeproject.com/Articles/472540/Alternative-tnsping-utility" rel="nofollow noreferrer">here</a>. And it also handles server lists in the <strong>ldap.ora</strong> file that includes multiple delimited port numbers.</p> <pre><code>private static string ResolveServiceNameLdap(string serviceName) { string tnsAdminPath = Path.Combine(@"C:\Apps\oracle\network\admin", "ldap.ora"); string connectionString = string.Empty; // ldap.ora can contain many LDAP servers IEnumerable&lt;string&gt; directoryServers = null; if (File.Exists(tnsAdminPath)) { string defaultAdminContext = string.Empty; using (var sr = File.OpenText(tnsAdminPath)) { string line; while ((line = sr.ReadLine()) != null) { // Ignore commetns if (line.StartsWith("#")) { continue; } // Ignore empty lines if (line == string.Empty) { continue; } // If line starts with DEFAULT_ADMIN_CONTEXT then get its value if (line.StartsWith("DEFAULT_ADMIN_CONTEXT")) { defaultAdminContext = line.Substring(line.IndexOf('=') + 1).Trim(new[] {'\"', ' '}); } // If line starts with DIRECTORY_SERVERS then get its value if (line.StartsWith("DIRECTORY_SERVERS")) { string[] serversPorts = line.Substring(line.IndexOf('=') + 1).Trim(new[] {'(', ')', ' '}).Split(','); directoryServers = serversPorts.SelectMany(x =&gt; { // If the server includes multiple port numbers, this needs to be handled string[] serverPorts = x.Split(':'); if (serverPorts.Count() &gt; 1) { return serverPorts.Skip(1).Select(y =&gt; string.Format("{0}:{1}", serverPorts.First(), y)); } return new[] {x}; }); } } } // Iterate through each LDAP server, and try to connect foreach (string directoryServer in directoryServers) { // Try to connect to LDAP server with using default admin contact try { var directoryEntry = new DirectoryEntry("LDAP://" + directoryServer + "/" + defaultAdminContext, null, null, AuthenticationTypes.Anonymous); var directorySearcher = new DirectorySearcher(directoryEntry, "(&amp;(objectclass=orclNetService)(cn=" + serviceName + "))", new[] { "orclnetdescstring" }, SearchScope.Subtree); SearchResult searchResult = directorySearcher.FindOne(); var value = searchResult.Properties["orclnetdescstring"][0] as byte[]; if (value != null) { connectionString = Encoding.Default.GetString(value); } // If the connection was successful, then not necessary to try other LDAP servers break; } catch { // If the connection to LDAP server not successful, try to connect to the next LDAP server continue; } } // If casting was not successful, or not found any TNS value, then result is an error message if (string.IsNullOrEmpty(connectionString)) { connectionString = "TNS value not found in LDAP"; } } else { // If ldap.ora doesn't exist, then return error message connectionString = "ldap.ora not found"; } return connectionString; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload