2
votes

I am developing a SharePoint 2010 timer job in C# which updates employee status (whether they are currently available or away from work) information retrieved from an SQL database to be updated and stored in an Employees SharePoint list (the desired approach is to be able to access any list I chose, not just one specified/hard coded list). I created a SharePoint empty project whose sole feature is the timer job with my event receiver class with custom code in the FeatureActivated and FeatureDeactived methods. The timer job class's Execute method gets the data using SqlClient and stores it into a dictionary object whose key value is the Employee ID and whose value is the status. The dictionary is then used to retrieve the employee records in the Employees SharePoint list and update the status.

My problem is, no matter what scope I have chosen for the timer job, I cannot access any SharePoint list I desire. I have tried to hard code in URLs for the lists, using the SPWeb and SPSite, just about anything. I have checked the sitecollection for my site, and I have 2 site collections ("/", "testsitecollection"), and the second one is not used at all.

For example" SPWeb web = site.OpenWeb(); SPList list = web.Lists["Employees"];

An exception is thrown: "List "Employees" cannot be found at http://www.mysite"

I was wondering if anyone had any input on the matter. In terms of source code, I followed the many examples on the web such as this: http://www.andrewconnell.com/blog/articles/CreatingCustomSharePointTimerJobs.aspx

All of the examples I found on the web for custom timer jobs update lists on the front site such as the Tasks list.

Thanks to anyone who adds input.

1
Just for a quick check.. you are able to access the "Employees" list from the Sharepoint site/UI. Right?Lorenzo Dematté
Also, to rule out permission issues.. have you tried to use SPSecurity.RunWithElevatedPrivileges?Lorenzo Dematté
please post a full example of the code you are usingint32
Yes, I can access the list through the site UI and yes I have tested permissions, and nothing came from it. What I eventually found was that in my Execute method for the timer job, following online tutorials, I had been using the targetGuid from the Execute parameter list to get the appropriate content database, and from that the appropriate site. This was the problem, so when I harded coded to get the first index in the content databases list and the first index in the sites list, it worked. This however adds another problem in the future, it is no longer dynamic and is fixed by code.J-man
int32: For legal reasons I cannot show the exact source code, but I can give you the overall -- public override Execute(Guid targetInstanceId) { SPWebApplication webApp = this.Parent as SPWebApplication; SPContentDatabase contentDb = webApp.ContentDatabases[0]; SPList list = contentDb.Sites[0].RootWeb.Lists["Employees"]; //remaining code is get info from SQL and store into list }J-man

1 Answers

1
votes

I have the same problem and I found it worked for me: You should restart OWSTimer.exe (window service in control panel--> administrative tools --> services). It is possible that you are applying the change but laest code is not yet picked up by Sharepoint timer service