I am working on an application that talks to Active Directory through an LDAP provider using both C # and C ++. The application runs on Windows 2003, 2008 and 2008 R2. I use anchor lines that look like this:
LDAP://mydomain.com/CN=Fred,DC=mydomain,DC=com LDAP://server.mydomain.com/CN=Fred,DC=mydomain,DC=com .
The application is responsible for the read and write operations in the directory. For example, in one scenario, he creates a new organizational unit, and then creates several users and groups in this new organizational unit. In another scenario, it is a directory view for an interactive user and allows the user to create a new group or user account.
So far I have used domain binding (the first example binds the line at the top), based on the MSDN recommendation
In most cases, the binding should not be unnecessarily tied to a single server. Active Directory Domain Services supports server binding, which means that Active Directory can be bound to the default domain without specifying a domain controller name
The problem occurs when there are several domain controllers in a domain; At the moment I will name them Lefty and Righteous. If I bind to the directory using LDAP://mydomain.com/blah , I implicitly connect to Lefty or Righty. Here is an example scenario of what happens:
- Snap to mydomain.com root. Active Directory gits choose Lefty as the server for communication.
- Create a new unit called Container. OU created by Lefty.
- Attempt to bind to a new unit. Active Directory guitars choose Righty as the server they need to talk to, so they crash because Righty doesn't know about the new unit.
- Wait 10-15 seconds and try again. Linking is performed when talking to any server.
In step 3, rebinding is not strictly required, but in some scenarios two different executables are involved, so I cannot use IADs or DirectoryEntry . Inside, I think Active Directory guts use DsGetDcName to choose which server to talk to, and the docs for this have a discussion of how it selects a domain controller and how it caches this information. Unfortunately, this is not what the application can really control, as far as I can tell. In some cases, I see applications connecting to one domain controller or another in series, but in other cases, the applications seem to switch between domain controllers (as described above), and everything does not work.
Workaround: Is this just a fundamental limitation of domain binding? I think the problem will disappear if I bind directly to a specific domain controller, but this greatly complicates the application code, so I was hoping to avoid this.