views:

85

answers:

1

Hi,

I am developing a SharePoint application which needs users from a specified Windows Server 2003 Active Directory Organizational Unit.

Firstly I wasn't concerned about the 'Dispose' and 'Close' operations on DirectoryServices objects. In this point the retrieve operations were quick and successful.

But this was causing 'Server is not operational' error after 2ish attempts. And this error makes the whole application operates worse like stopping other AD operations.

Then, I corrected this error by adding using statements on every DirectoryEntry, DirectorySearcher and SearchResultCollection objects.

Then I have reached a point that I have no longer get 'Server is not operational' error. But when I try to retrieve users from AD 1 or more times by using DirectorySearcher.FindAll method, the first one operates quick and successfully, others more slowly but successfully. It kinda takes the duration of a timeout. Could you please help me with my situation about this slow down?

Here is the sample code:

using (DirectoryEntry directoryEntry = new DirectoryEntry(connectionString, userName, password))
            {
                using (DirectorySearcher search = new DirectorySearcher(directoryEntry))
                {
                    search.SearchScope = SearchLevel.OneLevel;
                    search.ReferralChasing = ReferralChasingOption.All;
                    search.Filter = filter;
                    search.SizeLimit = 200;
                    //Limits the property count for search result
                    SetUserDirectorySearcherPropertiesToLoad(search);

                    using (SearchResultCollection result = search.FindAll())
                    {
                        foreach (SearchResult searchResult in result)
                        {
                            // Get user attributes
                        }}}}

Thanks in advance

A: 

Everything seems to be normal here. I am using something similar, the only mentionable difference is that I usually pass the "propertiesToLoad" parameter to the constructor of DirectoryEntry, as well as I pass the filter to the constructor of DirectorySearcher.

Another difference is that you are using "username" and "password" for the DirectoryEntry - maybe it's worth using the application pool identity? I typically do SPSecurity.RunWithElevatedPrivileges(method pointer) for these calls.

naivists
I tried both ways and that does not have any effect at all.Application pool identity does not have the required priviliges in Active Directory like adding any domain member to any group. So I have to take credentials from configuration file.
Melih Öztürk
can you post an example, how your variables `connectionString` and `filter` look like?
naivists
Melih Öztürk
No, it's quite OK with LDAP queries. I just thought the query might be too non-specific and you got very many results. But this does not seem to be the case. Is `ReferralChasing` set to `All` on purpose? I think this might take some time. However, it does not explain why the first execution is fast and the second is slow.
naivists
Thanks for the tip. I don't set ReferralChasing property on purpose. It was the most common DirectorySearcher property on code samples. I will try setting the property to None and look for the results when i got to work.
Melih Öztürk
I just tried what you suggest and Active Directory operations operates slight faster than usual on CRUD operations but not in this problem. Wait time still occurs. Maybe the problem occurs from consecutive operations on AD for a request in my applicaion. Application operates at least 5 connection for 1 operation which consists invokes, object updates and bringing object properties for the same object.
Melih Öztürk