Serve Laurijssen
Serve Laurijssen

Reputation: 9763

Moving and renaming AppFabric configuration database

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?

Upvotes: 1

Views: 2491

Answers (3)

Conure
Conure

Reputation: 150

The scripts provided by the other users did not work for me. I encountered exceptions. I was able to work around this issue by editing the registry on each host and restarting the service.

The connection string is stored here: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\AppFabric\V1.0\Configuration

The value is named "ConnectionString"

Under the user hive, there's another instance of the connection string. I don't know if you need to change this or not, but I did. HKEY_CURRENT_USER\Software\Microsoft\AppFabric\V1.0\Temp

That worked for me. Don't forget you also need to edit the ClusterConfig ConnectionString in DistributedCacheService.exe.config under C:\Program Files\AppFabric 1.1 for Windows Server

Upvotes: 2

Serve Laurijssen
Serve Laurijssen

Reputation: 9763

Since I can't stop the cluster I've tried to see if the connection string would be changed without restarting and basically just calling Remove-CacheAdmin and Add-CacheAdmin....it worked! Of course the script would have to be run on each host so not good for large setups but a restart is not really needed apparently

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"
    [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

    Remove-CacheAdmin
    Add-CacheAdmin -Provider $provider -ConnectionString $newConnectionString  

}

Upvotes: 2

stuartd
stuartd

Reputation: 73303

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

Upvotes: 1

Related Questions