Recently we did a move and a rename of an AppFabric configuration database.
The rename was from default name "AppFabricConfigurationDatabase" to "AppFabricPreOrdersConfiguration"
DistirbutedCacheService.exe.config was changed with the new database and server name
<clusterConfig provider="System.Data.SqlClient" connectionString="Data Source=NEWSERVER;Initial Catalog=AppFabricPreOrdersConfiguration;Integrated Security=True" />
and the service starts succesfully.
But from this point on the "caching administration powershell" does not start anymore because when use-cachecluster is called it still tries to connect to the old server / database.
Test connection failed for ConnectionString Data Source=OLDSERVER;Initial Catalog =AppFabricCacheConfigurationDatabase;
Use-CacheCluster : ErrorCode:SubStatus:Invalid provider and c onnection string read.
Where does powershell read those values from? Apparently not from the config file of the service but where then?
You need to call Remove-CacheAdmin
and then Add-CacheAdmin
to change the cache admin connection on each admin host
This Microsoft Powershell script - (.EXE download, script reproduced below) - changes the connection string on all hosts in a cluster.
param ([string] $provider, [string] $newConnectionString)
function Main {
if ( (! $provider) -or (! $newConnectionString))
{
Write-Host "Usage: ChangeConnString.ps1 <provider> <newConnectionString>"
exit(1)
}
Import-Module "DistributedCacheAdministration"
Import-Module "DistributedCacheConfiguration"
Use-CacheCluster
Write-Host "Stop the cache cluster if it is running"
$clusterRunnig=$true
&{
Stop-CacheCluster -EA Stop
}
trap [DataCacheException] {
#'Error Category {0}, Error Type {1}, ID: {2}, Message: {3} {4}' -f $_.CategoryInfo.Category, $_.Exception.GetType().FullName, $_.FullyQualifiedErrorID, $_.Exception.Message, $_.Exception.ErrorCode;
#12008: ErrorCode<ERRCAdmin008>:SubStatus<ES0001>:No hosts running in cluster
if ($_.Exception.ErrorCode -eq 12008)
{
write-host "Cluster is not running"
$clusterRunnig=$false
continue
}
}
[Reflection.Assembly]::LoadWithPartialName('Microsoft.ApplicationServer.Caching.Management') | Out-Null
[Reflection.Assembly]::LoadWithPartialName('System.Management.Automation') | Out-Null
[Reflection.Assembly]::LoadWithPartialName('System.Management.Automation.Runspaces') | Out-Null
SetCacheConnectionString $provider $newConnectionString
Write-Host "Connection string is altered on all the cache hosts. Now changing the connection string for cache admin"
Remove-CacheAdmin
Add-CacheAdmin -Provider $provider -ConnectionString $newConnectionString
if ($clusterRunnig -eq $true)
{
Write-Host "Starting the cache cluster..."
Start-CacheCluster
}
}
function SetCacheConnectionString {
param ([string] $provider, [string] $newConnectionString)
Write-Host "Parameters: " $provider " " $newConnectionString
$powerShell = [System.Management.Automation.PowerShell]::Create()
# Import the admin cmdlets module
$powerShell.AddCommand("Import-Module", $true);
$powerShell.AddParameter("Name", "DistributedCacheAdministration")
# Call the Invoke method to run the commands
$powerShell.Invoke();
$powerShell.Commands.AddCommand("Use-CacheCluster")
$powerShell.Commands.AddCommand("Get-CacheHost")
$commandResults = $powerShell.Invoke()
$powerShell.Dispose()
Write-Host "Number of hosts in the cluster " $commandResults.Count
foreach ($cacheHost in $commandResults)
{
Write-Host "Configuring the host " $cacheHost.HostName
Invoke-Command -ComputerName $cacheHost.HostName -ScriptBlock {param ($provider, $newConnectionString) Import-Module DistributedCacheConfiguration;Remove-CacheHost;Add-CacheHost -Provider $provider -ConnectionString $newConnectionString -Account 'NT Authority\NETWORK SERVICE'} -ArgumentList $provider, $newConnectionString
}
}
#
# Entry
#
Main