-1

I have a C# script I am trying to use to connect to an Oracle Directory Server Enterprise Edition So far i have had very little success. I am receiving a Unknown error (0x80005000) error message Can somebody tell me what I am doing wrong. I have been researching the web and most online boards say that this error message is because the LDAP in the path needs to be in uppercase letters. As you can see I have done that but still no luck.

Below is my code

 private static readonly string PATH = "LDAP://LDAPDEV.example.com:389/o=example.com";
 private static readonly string USERNAME = uid=SERVICE_USR,ou=ApplicationIDs,o=example.com";
 private static readonly string PASSWORD = "test1234";  


      string DN = "";

        // connect to determine proper distinguishedname
        DirectoryEntry Entry = new DirectoryEntry(Path, USERNAME, PASSWORD, AuthenticationTypes.None);

        try
        {
            // Bind to the native AdsObject to force authentication.
            Object obj = Entry.NativeObject;

            DirectorySearcher Search = new DirectorySearcher(Entry);
            Search.ReferralChasing = ReferralChasingOption.All
        }
        catch (Exception ex)
        {
            throw new Exception("Error looking up distinguishedname. ", ex);
        }
        finally
        {
            anonymousEntry.Close();
        }

        return DN;
    }

string sDomain="LDAPDEV.example.com:389"; 
string sDefaultOU = @"o=example.com"; 
string sServiceUser = @"uid=user,ou=ApplicationIDs,o=example.com"; 
string sServicePassword = "password"; 

try 
 {
PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, sDomain, sDefaultOU, ontextOptions.SimpleBind, sServiceUser,sServicePassword); 

 } 
 catch (Exception ex) 
 {
          ex.Message; 
 }
13
  • your connection string looks to be a bit off have you read any documentation on how to format a connection string using C# with LDAP or `Active Directory here is a stackoverflow posting you can use as an example stackoverflow.com/questions/15157746/… do some more research on your end thanks Commented Sep 18, 2014 at 15:46
  • Thanks for your response. Did you read my question? It appears the post you pointed me to is referring to AD connections. How about non-AD connections, which is what i am looking into. When i followed the instructions, i am still receiving errors DirectoryEntry entry = new DirectoryEntry("LDAP://address/DC=examples,DC=com", "username", "passwd"); the error i am receiving is "An invalid dn syntax has been specified" Any help you can is much appreciated Commented Sep 19, 2014 at 15:33
  • try changing your code and use PrincipalContext it's so much easier.. stackoverflow.com/questions/11561689/… Commented Sep 19, 2014 at 15:52
  • Using PrincipalContext, i am getting an "Object reference not set to an instance of an object." error message below is my code Am i missing something? string sDomain="LDAPDEV.example.com:389"; string sDefaultOU = @"o=example.com"; string sServiceUser = @"uid=user,ou=ApplicationIDs,o=example.com"; string sServicePassword = "pass"; try {PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, sDomain, sDefaultOU, ontextOptions.SimpleBind, sServiceUser,sServicePassword); } catch (Exception ex) {ex.Message, ex); } Commented Sep 19, 2014 at 17:54
  • can't read that code to clearly from comment post it as an amendment to your original question please Commented Sep 19, 2014 at 17:57

1 Answer 1

0

Here is something that you can use to get some information by using PrincipalContext look at this working example and replace the values with your domain name values.

 // if you are doing this via web application if not you can replace
 // the Request/ServerVariables["LOGON_USER"] 
 // with Environment.UserName; this will return your user name like msmith for example so var userName = Environvironment.UserName; 
 var userName = Request.ServerVariables["LOGON_USER"].Split(new string[] {"\\"}, StringSplitOptions.RemoveEmptyEntries);
 var pc = new PrincipalContext(ContextType.Domain,"yourdomain.com",null, null);
 var userFind = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, userName);

this is basically all you need to see the information like email address SamAccountName ect.. use the debugger to inspect all the property values available in the pc variable and userFind variable

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.