locked
SharePoint: Timer Job RRS feed

  • Question

  • Hi,

    I am using Sharepoint 2010. To meet our organizational requirements we created 17 site collections each with its own content database. Recently we have a scenario where we had to write our own timer job for a specific site collection so we created a timer job. Now when that job is triggered, it is triggered for 17 times(i guess each for the content DB). how can i fix it, just want that job to run once for the desired content db.

    Thanks in advance,


    _________ Fahad Ahmed Khan .NET Articles, Web Development, SharePoint and Project Server Custom Solution Provider
    Thursday, November 24, 2011 8:30 AM

Answers

  • I'm not sure a JobLockType of ContentDatabase will achieve what you want. You might like to consider the JobLockType.Job, and inside the Timer Job store a property that knows which site collection you want to act on.

    How are you creating the timer job? You could do so by using a SiteCollection feature, which when activated on a site creates the timer job and passes the id of the site collection into the constructor of the timer job (which in turn stores that site collection id ready for when the timer job executes)

    Hope that makes sense.

     

    • Proposed as answer by Aravind Lakshmanan Thursday, November 24, 2011 3:43 PM
    • Marked as answer by fodi30 Friday, November 25, 2011 6:01 AM
    Thursday, November 24, 2011 9:21 AM

All replies

  • You should be able to achieve this by using SPJobLockType.ContentDatabase: http://blogs.msdn.com/b/besidethepoint/archive/2011/11/13/sharepoint-timer-job-locks-and-scope.aspx
    Stefan Goßner
    Senior Escalation Engineer - Microsoft CSS
    This post is provided "AS IS" with no warrenties and confers no rights.
    Thursday, November 24, 2011 8:57 AM
  • I'm not sure a JobLockType of ContentDatabase will achieve what you want. You might like to consider the JobLockType.Job, and inside the Timer Job store a property that knows which site collection you want to act on.

    How are you creating the timer job? You could do so by using a SiteCollection feature, which when activated on a site creates the timer job and passes the id of the site collection into the constructor of the timer job (which in turn stores that site collection id ready for when the timer job executes)

    Hope that makes sense.

     

    • Proposed as answer by Aravind Lakshmanan Thursday, November 24, 2011 3:43 PM
    • Marked as answer by fodi30 Friday, November 25, 2011 6:01 AM
    Thursday, November 24, 2011 9:21 AM
  • Hi,

     

    Use  SPJobLockType.None in TimerJob constructor, then it will run only one time, even the perticlualr web application having many content db

     

     

    Thursday, November 24, 2011 11:04 AM
  • Hi,

     

    Use  SPJobLockType.None in TimerJob constructor, then it will run only one time, even the perticlualr web application having many content db

     

     

     
    Please don't self propose.  Either wait for the OP to confirm or a member of the community to do so for you.

    Steven Andrews | SharePoint Professional | http://www.twitter.com/backpackerd00d | https://baron72.wordpress.com/
    Thursday, November 24, 2011 11:09 AM
    Answerer
  • Hi fodi30,

    What is the Timer Job Feature scope? Is it "Site" scoped? 

    If it's not, you can change it to site scope, and then activate the feature only on Site Collection you want to run.

    Thursday, November 24, 2011 11:09 AM
  • Thanks guys for your posts...i was was using SPJobLockType.ContentDB, after reading your posts and searching a bit over net i tried chaning it to SPJobLockType.Job which fixed the issue for me as Paul mentioned in his post.

    Again thanks all for helping me out on this.


    _________ Fahad Ahmed Khan .NET Articles, Web Development, SharePoint and Project Server Custom Solution Provider
    Friday, November 25, 2011 6:01 AM