You probably have encountered it already some time ago. You want to check the status of your Distributed Cache Cluster and you login to a back-end server where there is no Distributed Cache component.
You open up Powershell and start with Use-CacheCluster. It fails. You failed. You need to login to a server which is an active member of the Distributed Cache Cluster to get the status, configuration, etc.
Now there is a simple solution which does not effect your application.
Some examples you might get when trying to connect to the AppFabric Distributed Cache cluster from a SharePoint server:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
PS D:\> Use-CacheCluster Use-CacheCluster : ErrorCode<ERRPS001>:SubStatus<ES0001>:Error in reading provider and connection string values. Please provide the values manually. At line:1 char:1 + Use-CacheCluster + ~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Connect-AFCacheClusterConfiguration], DataCacheException + FullyQualifiedErrorId : ERRPS001,Microsoft.ApplicationServer.Caching.Commands.ConnectAFCacheClusterConfigurationCommand PS D:\> Get-CacheHostConfig -ComputerName SP2013FE -CachePort 22233 Get-CacheHostConfig : ErrorCode<ERRPS013>:SubStatus<ES0001>:Error: No valid cluster settings were provided with Use-CacheCluster. At line:1 char:1 + Get-CacheHostConfig -ComputerName SP2013FE -CachePort 22233 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-AFCacheHostConfiguration], DataCacheException + FullyQualifiedErrorId : Microsoft.ApplicationServer.Caching.DataCacheException,Microsoft.ApplicationServer.Caching.Commands.GetAFCacheHostConfigurationCommand PS D:\> $ConnectionString = (Get-SPDatabase | ?{$_.Type -match "Configuration"}).DatabaseConnectionString PS D:\> Use-CacheCluster -ProviderType System.Data.SqlClient -ConnectionString $ConnectionString Use-CacheCluster : Could not find stored procedure 'GetEntry'. At line:1 char:1 + Use-CacheCluster -ProviderType System.Data.SqlClient -ConnectionString $Connecti ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Connect-AFCacheClusterConfiguration], ConfigStoreException + FullyQualifiedErrorId : Microsoft.ApplicationServer.Caching.ConfigStoreException,Microsoft.ApplicationServer.Caching.Commands.Connec tAFCacheClusterConfigurationCommand PS D:\> $Provider = "SPDistributedCacheClusterProvider" PS D:\> Use-CacheCluster -ProviderType $Provider -ConnectionString $ConnectionString Use-CacheCluster : ErrorCode<ERRCMS0006>:SubStatus<ES0001>:Error while loading the provider "SPDistributedCacheClusterProvider". Check HKEY_LOCAL_MACHINE -> SOFTWARE\Microsoft\AppFabric\V1.0\Providers\AppFabricCaching -> SPDistributedCacheClusterProvider. At line:1 char:1 + Use-CacheCluster -ProviderType $Provider -ConnectionString $ConnectionString + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Connect-AFCacheClusterConfiguration], DataCacheException + FullyQualifiedErrorId : ERRCMS0006,Microsoft.ApplicationServer.Caching.Commands.ConnectAFCacheClusterConfigurationCommand |
I have been on a gooze chase for a while because of articles like this:
use-cachecluster
use-cachecluster -Provider “System.Data.SqlClient” -ConnectionString “Data Source=dbmachine\instance;Initial Catalog=DatabaseName;Integrated Security=true”http://blog.milrr.com/2012/05/code-appfabric-diagnostic-powershell.html
Use-CacheCluster
Sets the context of your Windows PowerShell session to the desired cache cluster.When you start a Windows PowerShell session, you must first run this command. If it is on a cache host, you run the command with no parameters, because the parameters are taken from the cache configuration on the computer. If you are running it from a non-host computer, you can use the parameters below to specify the desired cache cluster.
Parameter (alias) descriptions are as follows:
Provider (P): The provider that is used to store the cluster configuration settings. This can be eitherSystem.Data.SqlClient or XML depending on how the configuration information is stored.
ConnectionString (C): The connection string to the database or location of the XML configuration file.https://msdn.microsoft.com/en-us/library/ff718177(v=azure.10).aspx
How to do it
Thankfully, there is a solution:
The Use-CacheCluster can be helped with the directions where to find the cluster configuration. All it needs is some registry entries.
No problems or errors will occur, you are not activating services or changing the config within SharePoint. Just the registry on the server(s) where you want to be able to look at the Cache Cluster.
This is, because every SharePoint 2013 server gets the same AppFabric installation, because its a prerequisite component.
That means the Powershell modules, DLL files and basic registry entries are already in place.
We only need to add a few properties.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
PS D:\> Get-ItemProperty "HKLM:\Software\Microsoft\AppFabric\V1.0\Configuration" AdminConfigured : 0 ServiceConfigured : 0 ConnectionString : Data Source=SQL2012-agl001.local.nl;Initial Catalog=iSWF_LAB2_Config;Integrated Security=True;Enlist=False;Pooling=True ;Min Pool Size=0;Max Pool Size=100;Connect Timeout=15 Provider : SPDistributedCacheClusterProvider PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\AppFabric\V1.0\Configuration PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\AppFabric\V1.0 PSChildName : Configuration PSDrive : HKLM PSProvider : Microsoft.PowerShell.Core\Registry PS D:\> Get-ChildItem "HKLM:\Software\Microsoft\AppFabric\V1.0\Providers\AppFabricCaching" Hive: HKEY_LOCAL_MACHINE\Software\Microsoft\AppFabric\V1.0\Providers\AppFabricCaching Name Property ---- -------- SPDistributedCacheClusterProvi DisplayName : Microsoft SharePoint AppFabric Caching Service Configuration Store Provider der Type : Microsoft.SharePoint.DistributedCaching.Utilities.SPDistributedCacheClusterCustomProvider, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c System.Data.SqlClient DisplayName : SQL Server AppFabric Caching Service Configuration Store Provider Type : Microsoft.ApplicationServer.Caching.SqlServerCustomProvider, Microsoft.ApplicationServer.Caching.SqlProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (default) : "C:\Program Files\AppFabric 1.1 for Windows Server\DistributedCache.SqlConfiguration.exe" |
We can create these very easy:
1 2 3 4 5 6 7 8 |
$ConnectionString = (Get-SPDatabase | ?{$_.Type -eq "Configuration Database"}).DatabaseConnectionString Set-ItemProperty "HKLM:\Software\Microsoft\AppFabric\V1.0\Configuration" -Name ConnectionString -Value $ConnectionString Set-ItemProperty "HKLM:\Software\Microsoft\AppFabric\V1.0\Configuration" -Name Provider -Value "SPDistributedCacheClusterProvider" New-Item -Path "HKLM:\Software\Microsoft\AppFabric\V1.0\Providers\AppFabricCaching\SPDistributedCacheClusterProvider" New-ItemProperty -Path "HKLM:\Software\Microsoft\AppFabric\V1.0\Providers\AppFabricCaching\SPDistributedCacheClusterProvider" -Name "DisplayName" -Value "Microsoft SharePoint AppFabric Caching Service Configuration Store Provider" -PropertyType "string" -Force New-ItemProperty -Path "HKLM:\Software\Microsoft\AppFabric\V1.0\Providers\AppFabricCaching\SPDistributedCacheClusterProvider" -Name "Type" -Value "Microsoft.SharePoint.DistributedCaching.Utilities.SPDistributedCacheClusterCustomProvider, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" -PropertyType "string" -Force |
Now, when we use Use-CacheCluster on a SharePoint 2013 server where Distributed Cache is not configured, it works!
Thanks Wouter!
You saved my time. Your solution works like a charm! 🙂
Thanks since more or less I work on the same issue but I did not find the complete solution.
Your solution is Awesome and completed you save my time thanks a lot
Regards