1

When i tried to Activate Feature of Timer Job It returns error : Access Denied

Scope of Feature is "Site"..

private static void CreateJob(SPSite site)       
 {          
  try        
    {
     SPSecurity.RunWithElevatedPrivileges(delegate()
     {               
     TenderTimerJob job = new TenderTimerJob(JobName, site.WebApplication);
     job.Properties.Add("SiteCollectionUrl", site.Url);
     SPMinuteSchedule minutes = new SPMinuteSchedule();
     minutes.BeginSecond = 0;
     minutes.Interval = 30;
     minutes.EndSecond = 30;
     job.Schedule = minutes;
     job.Update(); //Error Generates here
     });
    }
    catch (Exception ex){
     string str = ex.Message.ToString();
   }
}

3 Answers 3

6

One thing to remember when you are using site-scoped or site collection–scoped Features to install the timer jobs: The account that does the scheduling must have write permissions to the configuration database of the server farm. Usually, the identity of the application pool that is hosting the SharePoint site does not have permissions on the configuration database.

Add the below function in the .cs file of timer job in which you can also find "Execute" function.

protected override bool HasAdditionalUpdateAccess()
  {
       return true;
  }

This will solve you "Access Denied" issue .


2

When a timer job instance is created, it is persisted to the farm configuration database. Accessing this database for write purposes is a privileged operation; as a rule of thumb, only the farm service account (that is, the account under which OWSTIMER.EXE executes) or accounts that explicitly have the rights. So application pool account wouldn't work, as this this task requires farm level permissions. However, if you're developing in Visual Studio 2010 you can avoid automatic activation of features using Project-> Properties -> In the Active Deployment Configuration section select "No Activation"

4
  • I also tried without SpSecurity and my account is registered as Farm service account.. But Still not Working..:( Oct 17, 2012 at 8:05
  • Are you activating features using PowerShell or during development Visual Studio 2010? Oct 17, 2012 at 10:54
  • 1
    During Deployment from VS 2010.. right now it is not showing error while i deploy it.. but when i debug it and activate feature manually it is showing error "Access Denied".. Oct 17, 2012 at 11:04
  • @FalakMahmood does this allow non-farm account users to activate the feature? I don't see how disabling Activation on deployment allows for activation down the line
    – PT_C
    Sep 8, 2015 at 13:58
0

I ended up on this page as a result of a google search, but found this answer as well which helped me, summed up it says:

By default, attempting to instantiate a timer job from within the site collection context is going to fail. Attempting the operation in an elevated privilege block (via SPSecurity.RunWithElevatedPrivileges) is only going to result in the web application's application pool account context being used instead of the current user context; this only succeeds if the app pool account has rights to write to the farm configuration database.

for the full answer check https://stackoverflow.com/a/1038527/119387.

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.