The search service is not able to connect to the machine that hosts the administration component

Tue, Jan 24, 2012 3-minute read

Another example of “when SharePoint goes wrong.” On a dev machine, the search service mysteriously stopped working. I can’t pinpoint what caused it, but SP1 and a CU were recently applied and these seem like good candidates for breaking things. When trying to admin the search service, you would see the following error:

The search service is not able to connect to the machine that hosts the administration component. Verify that the administration component ’{guid}′ in search application ‘Search Service Application’ is in a good state and try again.

…and trying to modify the topology of the search, resulted in a spurious error:

An unhandled exception occurred in the user interface.Exception Information: Exception has been thrown by the target of an invocation.

Something was clearly unhappy. Rather than waste too much time, the simplest solution seemed to be to delete the search application and recreate it, which I duly did, via Central Admin, verified that DBs and application pools disappeared and recreated the search application, using new names and credentials. Same error. I wasted spent some looking at permissions and the usual array of logs, events and other candidates, ran PSConfig and other upgrades, all to no avail.

I figured I could create the search application via Powershell. Why should this make a difference? No idea, but worth a shot. Then thankfully, I found that someone had already done it for me. And yes, this resolved the issues. I can’t explain why seeing as this script shouldn’t do anything that the GUI doesn’t do.

Script:

Add-PSSnapin Microsoft.SharePoint.PowerShell

# 1.Setting up some initial variables. 
write-host 1.Setting up some initial variables. 
$SSAName = "ContosoSearch" 
$SVCAcct = "Contosoadministrator" 
$SSI = get-spenterprisesearchserviceinstance -local 
$err = $null

# Start Services search services for SSI 
write-host Start Services search services for SSI 
Start-SPEnterpriseSearchServiceInstance -Identity $SSI

# 2.Create an Application Pool. 
write-host 2.Create an Application Pool. 
$AppPool = new-SPServiceApplicationPool -name $SSAName"-AppPool" -account $SVCAcct

# 3.Create the SearchApplication and set it to a variable 
write-host 3.Create the SearchApplication and set it to a variable 
$SearchApp = New-SPEnterpriseSearchServiceApplication -Name $SSAName -applicationpool $AppPool -databasename $SSAName"_AdminDB"

#4 Create search service application proxy 
write-host 4 Create search service application proxy 
$SSAProxy = new-spenterprisesearchserviceapplicationproxy -name $SSAName"ApplicationProxy" -Uri $SearchApp.Uri.AbsoluteURI

# 5.Provision Search Admin Component. 
write-host 5.Provision Search Admin Component. 
set-SPenterprisesearchadministrationcomponent -searchapplication $SearchApp  -searchserviceinstance $SSI

# 6.Create a new Crawl Topology. 
write-host 6.Create a new Crawl Topology. 
$CrawlTopo = $SearchApp | New-SPEnterpriseSearchCrawlTopology

# 7.Create a new Crawl Store. 
write-host 7.Create a new Crawl Store. 
$CrawlStore = $SearchApp | Get-SPEnterpriseSearchCrawlDatabase

# 8.Create a new Crawl Component. 
write-host 8.Create a new Crawl Component. 
New-SPEnterpriseSearchCrawlComponent -CrawlTopology $CrawlTopo -CrawlDatabase $CrawlStore -SearchServiceInstance $SSI

# 9.Activate the Crawl Topology. 
write-host 9.Activate the Crawl Topology. 
do 
{ 
    $err = $null 
    $CrawlTopo | Set-SPEnterpriseSearchCrawlTopology -Active -ErrorVariable err 
    if ($CrawlTopo.State -eq "Active") 
    { 
        $err = $null 
    } 
    Start-Sleep -Seconds 10 
} 
until ($err -eq $null)

# 10.Create a new Query Topology. 
write-host 10.Create a new Query Topology. 
$QueryTopo = $SearchApp | New-SPenterpriseSEarchQueryTopology -partitions 1

# 11.Create a variable for the Query Partition 
write-host 11.Create a variable for the Query Partition 
$Partition1 = ($QueryTopo | Get-SPEnterpriseSearchIndexPartition)

# 12.Create a Query Component. 
write-host 12.Create a Query Component. 
New-SPEnterpriseSearchQueryComponent -indexpartition $Partition1 -QueryTopology $QueryTopo -SearchServiceInstance $SSI

# 13.Create a variable for the Property Store DB. 
write-host 13.Create a variable for the Property Store DB. 
$PropDB = $SearchApp | Get-SPEnterpriseSearchPropertyDatabase

# 14.Set the Query Partition to use the Property Store DB. 
write-host 14.Set the Query Partition to use the Property Store DB. 
$Partition1 | Set-SPEnterpriseSearchIndexPartition -PropertyDatabase $PropDB

# 15.Activate the Query Topology. 
write-host 15.Activate the Query Topology. 
do 
{ 
    $err = $null 
    $QueryTopo | Set-SPEnterpriseSearchQueryTopology -Active -ErrorVariable err -ErrorAction SilentlyContinue 
    Start-Sleep -Seconds 10 
    if ($QueryTopo.State -eq "Active") 
        { 
            $err = $null 
        } 
} 
until ($err -eq $null)

Write-host "Your search application $SSAName is now ready"