The goal is to have a web user interface with the option to create new site collections with new Content Database.

With the admin user I can manually in the CA create new Content Databases. I can also create a new site collection in this content database.

The idea was to create an event receiver (C#). If the user adds data to a table, the mentioned actions are to be executed.

Experiments: a) Console application - works!

using (SPSite site = new SPSite("http://sp2013")) {
  using (SPWeb spWeb = site.OpenWeb()) {
      SPWebApplication elevatedWebApp = spWeb.Site.WebApplication;
        elevatedWebApp.ContentDatabases.Add("sp2013", "WSS_Content_80_" + DateTime.Now.ToString("yyyymmddhhMMss"), null, null, 10, 15, 0);

b) Event Receiver - Only create site collections works, creation of content databases does not work! Error: Access Denied.

c) Web Service - Does not work! Error: Access Denied.

So, why do I get the error Access Denied when I can create site collections, but only content databases creation not go?

Finally I executed PS Script - but this also doesn´t work.

# AUTHOR: Paul Kotlyar
# CONTACT: [email protected]
# DESCRIPTION: sets an option on content web service that allows updating of SP Administration objects such as SPJobDefinition from content web applications
function Set-RemoteAdministratorAccessDenied-False()
    # load sharepoint api libs
    [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
  # update the web service

Maybe somebody knows a solution?

  • I have the same AccessDenied-problem when trying to create a content database via code. My user Interface is based on an application page (deployed as farm solution). You say "Solved it with an Farm Application page." Can you please give some more Information how you did this or maybe a piecew of sample code or the permissions of the active user?
    – user39865
    Feb 21, 2015 at 8:45

2 Answers 2


The code in console application works as you may be logged in as a Farm admin. The code in event receiver will fail even if it is run using elevated privileges i.e. app pool account unless the app pool account is added into Farm administrators group. The app pool account has permissions on content database, whereas it is the farm admin account which has access to config Database and creating a content database for a web application means having access on config database.

  • The execution user is in the Farm administrators group. Feb 19, 2015 at 9:18

Solved it with an Farm Application page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.