I was recently working on a SharePoint issue. The issue was that we were unable to rename the Property database or Crawl database in central admin site.

Here is the scenario:

We have provisioned a Search Service application using PowerShell. The script used by our customer to create the Search Service application was taken from a blog on internet. (Almost all blogs have same simple script to create Search Service application). The Search Service application is up and running fine without any issues.

The present requirement was to rename the Search Property and Crawl databases to match the organization standards.

For example:

SSA_Property_DB to SSA_Property_DB_renamed

SSA_Crawl_DB to SSA_Crawl_DB_renamed

We tried to rename the database through UI as follows:

· In Central Admin Site, go to the Search Service application. Under “Search Application Topology" click on Modify.

· Under Databases, click the Property database --> Edit Properties. Enter the new name in the Database Name field.

· Click OK followed by Apply Topology Changes.

· At this stage, it should show "Processing" in UI.

It takes at least 6 to 7 minutes to complete in UI. If you check the SQL server during this time, a new database with the specified name is created. The data from the original property DB is copied to the new database.

Now, the Issue:

After the task is completed, the old DB is supposed to be deleted. However in our case, the old database still remains. We had two Property databases in the Search Application Topology, old database as well as the new one. We are unable to delete it manually as well. We were able to reproduce this on my test environment too.

The issue reproduces every time when we use the PowerShell to create Search Service application. If we create the Search Service application using UI, we are able to successfully rename the database (The old DB is deleted)

Cause:

The problem is in the script we use to create the Search Service application. If we see any blogs on net for creating the Search Service application using PowerShell, the skeleton of script would be something like this:

1. We start the search services using Start-SPEnterpriseSearchServiceInstance and create a new application pool using new-SPServiceApplicationPool

2. Create the Search Application using New-SPEnterpriseSearchServiceApplication and a proxy using new-spenterprisesearchserviceapplicationproxy

3. Provision Admin component using set-SPEnterprisesearchadministrationcomponent

4. Create a new Crawl Topology using New-SPEnterpriseSearchCrawlTopology

5. Create a Crawl component using New-SPEnterpriseSearchCrawlComponent and activate the Crawl Topology.

6. Create a Query component using New-SPEnterpriseSearchQueryComponent and activate the query Topology.

In the step 5 and 6, we always add new crawl and query topology and activate them. We never delete the existing one (which is created when we create a new search service application). So, we end up having two query topologies and both have references to the property database. That is the reason why we face issue renaming the Property database. It will not be deleted. Same happens with crawl topology too.

If we compare the properties of the Search Service Application that were created via PowerShell and UI, we see the following difference:

clip_image002

Solution:

We need to modify the PowerShell script to create Search Service Application. To be specific, we need to remove the existing crawl/query topology after provisioning the Search Service application.

I have written an updated PowerShell script to achieve the same. It creates a Search Service Application in the similar way that UI creates. We can then successfully rename the property or crawl databases from UI.

I am posting the script here:

Disclaimer:

Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment. THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. We grant you a nonexclusive, royalty-free right to use and modify the Sample Code and to reproduce and distribute the object code form of the Sample Code, provided that. You agree: (i) to not use Our name, logo, or trademarks to market Your software product in which the Sample Code is embedded; (ii) to include a valid copyright notice on Your software product in which the Sample Code is embedded; and (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and against any claims or lawsuits, including attorneys’ fees, that arise or result from the use or distribution of the Sample Code.

##### *********************************************

# This is a sample script. It is provided as is. Please modify it and fine tune it as per your environment and business needs.

# In no way this is to be considered as a production ready script.

# Environment specific settings

$databaseServerName = "<DBservername>"

$searchServerName = "<Searchservermachine>"

$saAppPoolName = "<SSA_Appoolname>"

$appPoolUserName = "<domain\username>"

$searchSAName = "<SSA name>"

$DBName = "<SSA DB name>"

# Creating Application pool

$saAppPool = Get-SPServiceApplicationPool -Identity $saAppPoolName -EA 0

if($saAppPool -eq $null)

{

Write-Host " Creating Service Application Pool..."

$appPoolAccount = Get-SPManagedAccount -Identity $appPoolUserName -EA 0

if($appPoolAccount -eq $null)

{

Write-Host " Please supply the password for the Service Account..."

$appPoolCred = Get-Credential $appPoolUserName

$appPoolAccount = New-SPManagedAccount -Credential $appPoolCred -EA 0

}

$appPoolAccount = Get-SPManagedAccount -Identity $appPoolUserName -EA 0

if($appPoolAccount -eq $null)

{

Write-Host " Cannot create or find the managed account $appPoolUserName, please ensure the account exists."

Exit -1

}

New-SPServiceApplicationPool -Name $saAppPoolName -Account $appPoolAccount -EA 0 > $null

}

# Creating Search Service application

Write-Host " Creating Search Service and Proxy..."

Write-Host " Starting Services..."

Start-SPEnterpriseSearchServiceInstance $searchServerName

Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $searchServerName

Write-Host " Creating Search Application..."

$searchApp = New-SPEnterpriseSearchServiceApplication -Name $searchSAName -ApplicationPool $saAppPoolName -DatabaseServer $databaseServerName -DatabaseName $DBName

$searchInstance = Get-SPEnterpriseSearchServiceInstance $searchServerName

Write-Host " Creating Administration Component..."

$searchApp | Get-SPEnterpriseSearchAdministrationComponent | Set-SPEnterpriseSearchAdministrationComponent -SearchServiceInstance $searchInstance

# Crawl component

Write-Host " Creating Crawl Component..."

$InitialCrawlTopology = $searchApp | Get-SPEnterpriseSearchCrawlTopology -Active

$CrawlTopology = $searchApp | New-SPEnterpriseSearchCrawlTopology

$CrawlDatabase = ([array]($searchApp | Get-SPEnterpriseSearchCrawlDatabase))[0]

$CrawlComponent = New-SPEnterpriseSearchCrawlComponent -CrawlTopology $CrawlTopology -CrawlDatabase $CrawlDatabase -SearchServiceInstance $searchInstance

$CrawlTopology | Set-SPEnterpriseSearchCrawlTopology -Active

Write-Host -ForegroundColor white " Waiting for the old crawl topology to become inactive" -NoNewline

do {write-host -NoNewline .;Start-Sleep 6;} while ($InitialCrawlTopology.State -ne "Inactive")

$InitialCrawlTopology | Remove-SPEnterpriseSearchCrawlTopology -Confirm:$false

# Query component

Write-Host " Creating Query Component..."

$InitialQueryTopology = $searchApp | Get-SPEnterpriseSearchQueryTopology -Active

$QueryTopology = $searchApp | New-SPEnterpriseSearchQueryTopology -Partitions 1

$IndexPartition= (Get-SPEnterpriseSearchIndexPartition -QueryTopology $QueryTopology)

$QueryComponent = New-SPEnterpriseSearchQuerycomponent -QueryTopology $QueryTopology -IndexPartition $IndexPartition -SearchServiceInstance $searchInstance

$PropertyDatabase = ([array]($searchApp | Get-SPEnterpriseSearchPropertyDatabase))[0]

$IndexPartition | Set-SPEnterpriseSearchIndexPartition -PropertyDatabase $PropertyDatabase

$QueryTopology | Set-SPEnterpriseSearchQueryTopology -Active

Write-Host -ForegroundColor white " Waiting for the old query topology to become inactive" -NoNewline

do {write-host -NoNewline .;Start-Sleep 6;} while ($InitialQueryTopology.State -ne "Inactive")

$InitialQueryTopology | Remove-SPEnterpriseSearchQueryTopology -Confirm:$false

# Creating proxy

Write-Host " Creating Proxy..."

$searchAppProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name "$searchSAName Proxy" -SearchApplication $searchSAName > $null

Write-Host "Search Service Application created successfully"

##### *********************************************

In my next post, I will include the script to fix the existing Search Service Applications (The SSAs which are already created using the problem script, whose Crawl and Property databases cannot be renamed)

Part 2   at :  http://blogs.msdn.com/b/spses/archive/2013/04/23/sharepoint-2010-search-service-application-old-databases-not-removed-when-we-try-to-rename-the-property-database-or-crawl-database-using-central-admin-site-for-the-search-service-application-that-was-provisioned-via-powershel.aspx

 

Author: Pradeep Martin Anchan [MSFT]