views:

69

answers:

2

Hi,

I guess starting a timer job from within the code required Farm admin credetials. However, i need to start a timer job from a web part that will be used in any site. Now when i try to start the job it gives me access denied error and obviously so as app pool identity is not farm admin. Any ideas on how to resolve this issue?

Thanks,

+1  A: 

Your are right. To start a timer job the app pool user has to be farm administrator. Since starting a timer job requires you to update a SPJobDefinition object with an SPSchedule. The SPJobDefinition is a SPPersistedObject which is stored in the SharePoint Config Database. Only farm administrators can write into this db.

I don't see a way to get pass this issue.

Workaround: Depending on your requirements you could write a master job that runs on regular basis. This job could query a SharePoint list and start another job defined by such a list item. Since the master job runs under the Farm Administrator account, the job would be able to start a new timer job.

Jason
+1  A: 

Timer jobs run as the farm administrator and are not intended to be triggered directly by an end-user. Since some jobs may be resource intensive, only the farm admin can create new jobs or modify the schedule for existing jobs.

One solution is to use the SPWorkItem infrastructure to queue user tasks which are then processed by a custom timer job derived from SPWorkItemJobDefinition. Your webpart would call SPSite.AddWorkItem to add the work item. When your timer job runs, it will look for any work items with the matching WorkItemType GUID and invoke the ProcessWorkItem overload.

Joel Fillmore