Add content database access denied

09/06/2015 15:43

I was fighting with Access Denied error when creating Content Database from C# code of sharepoint context (Console application was working)

I used code in elevated privileges, my web application pool account had following permissions

- in SQL Server - public, dbcreator, sysadmin, securityadmin

- was SPShellAdmin

- farm administrator

and it wasn't still enough

Then I found following article

unclepaul84.blogspot.sk/2010/06/sppersistedobject-xxxxxxxxxxx-could-not.html

with script which worked for me

Here it is

DON'T FORGET RUN IISRESET AFTER SCRIPT COMPLETITION


function Set-RemoteAdministratorAccessDenied-False()
{
 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration") > $null

 # get content web service
 $contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
 # turn off remote administration security
 $contentService.RemoteAdministratorAccessDenied = $false
 $contentService.Update()
}

Set-RemoteAdministratorAccessDenied-False