Timer Job - Error
-
Wednesday, August 22, 2012 6:45 PM
Hi,
Can someone please tell me why I am getting a null reference error in Execute method of my timer job implementation class?
SPWebApplication webApplication = this.Parent as SPWebApplication; SPContentDatabase contentDb = webApplication.ContentDatabases[targetInstanceId];
Second line is where I am getting error. For some reason, it is not finding the content database since contentDB is returned as null.
Any ideas?
Thanks
All Replies
-
Wednesday, August 22, 2012 6:52 PM
public override void Execute(Guid targetInstanceId) { try { // get a reference to the current site collection's content database SPWebApplication webApplication = this.Parent as SPWebApplication; SPContentDatabase contentDb = webApplication.ContentDatabases[targetInstanceId]; -
Thursday, August 23, 2012 7:07 AM
Hi diffident!
I haven't found detailed description of targetInstanceId parameter. This article says it can contain the GUID of WebApplication.
Высказанное мною здесь - мои личные взгляды, а не позиции корпорации Microsoft. Вся информация предоставляется "как есть" без каких-либо гарантий.
- Edited by IAfanasovMicrosoft Employee Thursday, August 23, 2012 7:08 AM
-
Thursday, August 23, 2012 5:05 PM
Thanks IAfanasov.
In that article they never use targetInstanceId in the execute method. They are referencing the first site collection in that web app but that is not what I want.
I want to be able to get the reference to that first site collection from where the job is running.
-
Thursday, August 23, 2012 5:44 PM
Timer job runs on level of web app or service app. Not on level of site collection. May be you need SPAllSiteJobDefinition? It works on level of web app and iterates all site collections of that web app.
Высказанное мною здесь - мои личные взгляды, а не позиции корпорации Microsoft. Вся информация предоставляется "как есть" без каких-либо гарантий.
- Marked As Answer by Lhan HanModerator Sunday, September 02, 2012 1:36 AM
-
Friday, August 24, 2012 8:33 PM
Thanks IAfanasov!
I was able to make some progress by not using targetInstanceId anymore. However, I do have a question for you.
My timer job's feature's scope is set to "WebApplication" which means timer job got activated for each and every web application but that is not what I wanted.
How can I restrict/modify it so that there is only one timer job running in the entire farm?
Thanks!

