There are some mysterios errors on my SharePoint farm. After reading tons of log files I found some hints to problems with the “Session State Service” of SharePoint 2010.
I found this Cmdlets in PowerShell for controlling this service:
Enable-SPSessionStateService Disable-SPSessionStateService Get-SPSessionStateService Set-SPSessionStateService
I tried to enable the service with the first Cmdlet. – This was the resulting error:
Error message: “Microsoft SharePoint Server session state could not find the Session State Service. Contact your farm administrator.”
There is no information about this error in the internet. (Till now )
MY SOLUTION FOR MY PROBLEM (may be it does not help you in your special situation. It’s “experimental”!!!):
I created a PowerShell script for re-creating the Session State Service and its Service Application.
Before you go on: Make sure, the Windows service “ASP.NET State Service” is running. (I set it to start automatically during system startup.)
This is the resulting script:
#region Check x64 host if( [System.IntPtr]::Size -ne 8) { Write-Error "Please use a x64 PowerShell host!" return } #endregion #region Load SharePoint SnapIn and DLL Remove-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #Check available SharePoint Cmdlets if( (Get-Command -Noun SPWeb*) -eq $null ) { Write-Error "SharePoint SnapIn not loaded. SharePoint cmdlets missing!" return } #endregion cls $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local $services = $farm.get_Services() #get all SharePoint services $sessionStateService = ($services | ? { $_.TypeName -like "*session state*" } ) #find the existing Session State Service -> it was "NULL" for me! if( $sessionStateService -eq $null ) { #Recreate the Service $newSessionStateService = New-Object Microsoft.Office.Server.Administration.SessionStateService ("", $farm) $newSessionStateService.Id = [System.Guid]::NewGuid() $newSessionStateService.Name=[String]::Empty $newSessionStateService.Update() $farm.Update() $newSessionStateService.Provision() $newSessionStateService.Name=[String]::Empty $newSessionStateService.Update() } $services = $farm.get_Services() $sessionStateService = ($services | ? { $_.TypeName -like "*session state*" } ) $servers=(Get-SPServer) #Create service instances on all application servers of the SharePoint farm $servers | % { if( $_.Role -eq "Application" ) { $currentSessionStateSvcOnServer = ($_.ServiceInstances | ? { $_.TypeName -like "*session state*" } ) if( $currentSessionStateSvcOnServer -eq $null ) { #write-host $_.Name $server.Role $_.gettype().fullname #To create a service instance you must use a "protected" constructor [type]$t = "Microsoft.SharePoint.Administration.SPServiceInstance" -as "Type" $p = @( ("string" -as [Type]), ("Microsoft.SharePoint.Administration.SPServer" -as [Type]), ("Microsoft.SharePoint.Administration.SPService" -as [Type]) ) $c = $t.GetConstructor([System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Instance,$null, $p, $null) #these are the parameters for creating a service instance by using the protected constructor [Object[]]$params = @([Object]"Session State Service Instance", [Object]([Microsoft.SharePoint.Administration.SPFarm]::Local.Servers[$_.Name]), [Object]([Microsoft.SharePoint.Administration.SPFarm]::Local.Services[$sessionStateService.Id])) $newSvcInstance = $c.Invoke($params) #update & provisioning $newSvcInstance.Update() $newSvcInstance.Provision() } } } if( (Get-SPSessionStateService -ErrorAction SilentlyContinue) -ne $null ) { Write-Host "Successfull :-)" -ForegroundColor Green } else { Write-Host "Failed :-(" -ForegroundColor Red }
After that, the “Enable-SPSessionStateService” works:
(Spend me 1 1/2 days.)
You can use this script to delete the Session State Service, e.g. if some script parts does not work as expected. ONCE MORE: USE IT CAREFULLY AND AT YOUR OWN RISK!!!
#region Check x64 host if( [System.IntPtr]::Size -ne 8) { Write-Error "Please use a x64 PowerShell host!" return } #endregion #region Load SharePoint SnapIn and DLL Remove-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #Check available SharePoint Cmdlets if( (Get-Command -Noun SPWeb*) -eq $null ) { Write-Error "SharePoint SnapIn not loaded. SharePoint cmdlets missing!" return } #endregion cls $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local Get-SPServiceApplication | ? {$_.GetType().FullName -eq "Microsoft.Office.Server.Administration.SessionStateServiceApplication"} | Remove-SPServiceApplication $farm.Services | ? { $_.TypeName -like "*session state*" } | % { $_.Instances | % { $_.Delete() } $_.Delete() }
Thanks this was a huge help! Another good article for some background on session states: http://blogs.msdn.com/b/markarend/archive/2010/05/27/using-session-state-in-sharepoint-2010.aspx
Pingback: SharePoint 2010 Session State Service « BasementJack