0

I have an SPJobDefinition (WSS) that runs each hour. Based on some values, and if met, it adds an item to the calendar list. This calendar list has an event receiver attached to the ItemAdded event.

When the job does trigger and adds the item, parts of the code executes. What I mean is that it wont' write to the eventlog and it seems to have problems reading from the web.config file.

If I manually add an item to the calendar list, using my credentials, everything works fine. That is, I have events in the eventlog and the items are read from the web.config file.

I can see where System Account is adding the item in the Calendar list. I've tried adding System Account to the groups with full control and I'm still having a problem.

Is there something else I have to look at to get this to work? I've checked the pool user and it's Network Service; I've since added them to the group as well.

I'm not sure where else to look.

Thanks

Updated (this is the code I use to write to the eventlog)

try
{
  System.Security.Principal.WindowsImpersonationContext wic = System.Security.Principal.WindowsIdentity.Impersonate(IntPtr.Zero);
  EventLog.WriteEntry(source, message, type);
  wic.Undo();
}
catch (Exception)
{
}
1
  • Timer jobs are run by the account running OWSTIMER.exe. Did you add that account with appropriate permissions?
    – user6024
    May 14, 2012 at 18:19

1 Answer 1

1

Writing to the eventlog could be due to missing windows permissions.

The timer job runs in a windows service which doesn't have a web.config. An event receiver runs in whatever process causing the event. So if you try to read the web.config of the current process it'll fail.

If you try to reach out into the file system to read the web.config, then it might be windows permissions again.

Adding users to SharePoint groups can't help you with access to EventLog or files, these are windows objects not SharePoint objects.

When running from a Timer Job the Impersonate(IntPtr.Zero); isn't changing anything. It impersonates the process account which is already the one running.

3
  • Hi Per - I updated my original question to show the code I use to write to the EventLog. You think that might still be the problem?
    – DrZ
    May 14, 2012 at 18:23
  • Added comments in answer May 14, 2012 at 18:45
  • So it sounds like writing to the EventLog is out of the question for this process. As for the web.config file, it sounds like I have to come up with another solution. Thank you for your help!
    – DrZ
    May 14, 2012 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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