2012-06-07 45 views
1

我們在使用活動目錄和移動/重命名OU時遇到問題。這隻發生在我們在兩個域控制器之間進行復制時。我們得到的例外是:活動目錄和多個DC的複製問題

System.ServiceModel.FaultException:服務器上沒有這樣的對象。 (異常來自HRESULT:0x80072030)

當我們嘗試移動並重命名活動目錄中的OU時,我們得到了此錯誤消息的變體。這裏是有問題的代碼:

PrincipalContext context = GetPrincipalContext(); 

using (UserPrincipal principal = UserPrincipal.FindByIdentity(context, IdentityType.Guid, id.ToString())) 
{ 
    if (principal == null) 
    { 
     throw new InvalidOperationException(); 
    } 

    string oldEmail = principal.EmailAddress; 

    principal.EmailAddress = newEmail; 
    principal.Save(); 

    DirectoryEntry entry = principal.GetUnderlyingObject() as DirectoryEntry; 
    DirectoryEntry targetDirectoryEntry = null; 
    string target = null; 

    // Access the underlying DirectoryEntry to rename it: 
    try 
    { 
     if (entry == null) 
     { 
      throw new InvalidOperationException(); 
     } 

     entry.RefreshCache(); 
     entry.Rename(string.Format("CN={0}", newEmail)); 

     // Move the DirectoryEntry to the correct location. 
     target = BuildOrganizationalUnitName(newEmail); 

     targetDirectoryEntry = FindDirectoryEntry(target); 
     if (targetDirectoryEntry == null) 
     { 
      throw new InvalidOperationException(); 
     } 
     entry.MoveTo(targetDirectoryEntry); 
     entry.CommitChanges(); 
    } 
    catch (Exception e) 
    { 
     // do some logging 
    } 
    finally 
    { 
     if (entry != null) 
     { 
      entry.Dispose(); 
     } 

     if (targetDirectoryEntry != null) 
     { 
      targetDirectoryEntry.Dispose(); 
     } 
    } 
} 

所以我有兩個問題:

  1. 這有什麼錯與上面的代碼,這是試圖 移動和重命名OU?
  2. 如果不是,有沒有辦法確保兩個DC在移動/重命名後保持同步?

回答

0

你或許應該試圖將它移到前提交修改到重命名。

entry.Rename(string.Format("CN={0}", newEmail)); 
entry.CommitChanges(); // add this line