Unable to populate AD containers while creating a new AD sync connection, It times out or do not respond

Issue

When you try to create a new user profile sync connection to Active Directory. You provide the details of AD and try to populate the containers. The page stop responding and you observer SharePoint will keep on querying forever and never get completed or it times out with below error

Webpage error details

Message:
Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500

Line: 5 Char: 62099 Code: 0 URI: <URL>

 

If you check in the ULS , you will see below errors w3wp.exe

w3wp.exe (0x15E4)                0x100C    SharePoint Portal Server        User Profiles           ae6u        High                EditDSServer.PopulateContainers(): System.Threading.ThreadAbortException: Thread was being aborted.     at System.Web.UI.WebControls.TreeView.CollapseAll()     at Microsoft.SharePoint.Portal.UserProfiles.AdminUI.EditDSServer._GetContainersAndFillTreeView(LdapConnection ldapConnection, Boolean useOnlyPreferredDomainControllers)     at Microsoft.SharePoint.Portal.UserProfiles.AdminUI.EditDSServer.PopulateContainers(Object sender, EventArgs args).       c266e43d-1c10-4254-9ac8-f4371ac13a4c
w3wp.exe (0x15E4)                0x100C    SharePoint Foundation           Runtime  tkau         Unexpected                System.Web.HttpException: Request timed out.  c266e43d-1c10-4254-9ac8-f4371ac13a4c

Cause:

HTTP timeout while populate the AD containers. This issue occurs when your domain controllers not responding in a timely manner due to AD or network  issues.

Resolution:

  1. Confirm your SharePoint server has connectivity with your DC server

  2. Confirm you have proper permissions as per https://technet.microsoft.com/en-us/library/ee721049(v=office.14).aspx

  3. If it is a timeout issue while populating AD containers, follow below steps to Increase the AD query timeout value

  4. Right click on the web.config file in the above folder to edit it

    Go to Line 6 <httpRuntime executionTimeout= "360 "> Change the
    executionTimeout value from 360 to 3600

  5. Increase the following timeout values in SharePoint to something above 15 minutes e.g. 30 minutes

  6. Check if AD containers are displayed in SharePoint. If not follow below additional steps.

  7.  $upaAppProxy = Get-SPServiceApplicationProxy | ? {$_.name -like 'User Profile Service Proxy'}

    $upaAppProxy.ImportConnAsyncTimeout = 1800 //This value is in seconds

    $upaAppProxy.Update()

  8. $upaApp = Get-SPServiceApplication | ? {$_.name -like 'User Profile Service'}

    $upaApp. FIMWebClientTimeOut = 1800000 //This value is in milliseconds

    $upaApp.Update()

  9. $upaAppProxy = Get-SPServiceApplicationProxy | ? {$_.name -like 'User Profile Service Proxy'}

    $upaAppProxy.LdapConnectionTimeout = 1800 //This value is in seconds

    $upaAppProxy.Update()

  10. This will allow you to populate AD user containers and create new sync connection. If still gets timeout issue, then investigate the SharePoint, AD connectivity errors.