Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers 2

try using

SPJobLockType.ContentDatabase
share|improve this answer
    
no, that's what it was originally. that SPJobLock runs the timer job over each content database. –  Nacht Oct 18 '12 at 10:14
add comment
up vote 2 down vote accepted

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.

share|improve this answer
    
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 Jan 9 '13 at 4:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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