0

I have developed a custom timer job, inheriting from SPJobDefinition. It currently runs on two content databases, and I would like it to run on only one.

I have created this timer job using the following constructor:

public HiddenTitleJob(string jobName, SPWebApplication webApplication) :
    base(jobName, webApplication, null, SPJobLockType.Job)
{
    this.Title = "Hidden Title Timer Job";
}

Many web sources, including this question, seem to suggest that SPJobLockType.Job prevents my timer job from running on more than one content database, but it hasn't worked for me. Microsoft's documentation is very vague, it only says "Locks the job to prevent it from running on more than one machine" - it says nothing about content databases.

2

This can only be done by adding code to the Execute method of your timer job, like so:

public override void Execute(Guid contentDbId)
{
    SPSite siteCollection = new SPSite(mySiteCollectionUrl);
    if (siteCollection.ContentDatabase.Id.Equals(contentDbId))
    {
        // timer job code
    }
}

Neither of the three SPJobLockTypes prevent it from running on all content databases for a single web application.

  • actually i cant remember why i thought SPJobLockType.Job would ever run more than once... I will be using SPJobLockType.Job without the above code until i notice it running more than once, or someone else can clarify – Nacht - Reinstate Monica Jan 9 '13 at 4:46
0

try using

SPJobLockType.ContentDatabase
  • no, that's what it was originally. that SPJobLock runs the timer job over each content database. – Nacht - Reinstate Monica Oct 18 '12 at 10:14

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.