0

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: unclepaul84@gmail.com
# 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
 $contentService.Update()
}

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 '15 at 8:45
0

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. – user3752660 Feb 19 '15 at 9:18
0

Solved it with an Farm Application page.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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