I am stuck onto a very strange situation.
I have a workflow that i use to provision new site on my web application. This workflow uses one custom workflow activity to provision the site using followoing statement.
—other code omited for clarity—-
SPSiteCollection.Add()
This statement is throwing followign exception when my applicaiton pool account is not same as Central Admin applicaiton pool account.
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at
Microsoft.SharePoint.SPGlobal.HandleUnauthorizedAccessException(UnauthorizedAccessException
ex) at
Microsoft.SharePoint.Library.SPRequest.CreateSite(Guid
gApplicationId, String bstrUrl, Int32
lZone, Guid gSiteId, Guid gDatabaseId,
String bstrDat
after a lot of googling and findings i have zeroed down to the Applicaiton Pool account permission.
The workflow code always runs under the System account (the applicaiton pool identity). In order to create new SharePoint site collection, the application pool requires access to “SharePoint_Config” database.
When my web application is running under the applicaiton pool credential of Central Admin, it has all the access to the configuration database. But when i am running the under any other applicaiton pool identity which has less permission. it throws exception, even if i give DBO permission to the applicaiton pool account in the Configuration database.
My applicaiton event log has following entry :-
Event Source: Windows SharePoint
Services 3 Event Category: Database
Event ID: 3760 Date: 2/3/2010
Time: 2:36:16 AM User: N/A
Computer: SHAREPOINT20 Description:
SQL Database ‘SharePoint_Config’ on
SQL Server instance ‘houspsr001’ not
found. Additional error information
from SQL Server is included below.Cannot open database
“SharePoint_Config” requested by the
login. The login failed. Login failed
for user ‘DOMAIN\WebAppPool’.For more information, see Help and
Support Center at
http://go.microsoft.com/fwlink/events.asp.
My question is…is it mendatory to run such code under the applicaiton pool account of central admin.
Any workaround for this….?
My question
Finally the access denied issue has been resolved. As I motioned in my previous email, the issue was due to insufficient permission to my application pool identity.
My workflow was using the ElevatedPrevilages to provision a site collection, and it used to get Access Denied from the database since it did not had permission to modify SharePoint_Config database.
Resolution
In order to resolve this issue i had to impersonate the application pool identity of Central Admin. Here is the required method for impersonating Central Admin application pool user.
And then my code to create site collection looks like:-