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

Can anyone provide any ideas on why the below query returns nothing when inside a custom timer job. But when run from a console program it returns results. Note, both console program and OWSTimer.exe are running as the same user "Administrator". Thank you for any suggestions.

SPContentDatabase contentDb = webApp.ContentDatabases[contentDbId];
SPQuery query = new SPQuery();
IList<Engagement> items = new List<Engagement>();
SPFieldLookupValue valSection;

query.ViewFields = @"<FieldRef Name=""FileRef"" /><FieldRef Name=""Section"" />";
query.Query = "<Where><And>" +
        "<Gt><FieldRef Name=\"Modified\" /><Value IncludeTimeValue=\"TRUE\" Type=\"DateTime\">2012-08-22T09:15:15Z</Value></Gt>" +
        "<IsNotNull><FieldRef Name=\"Section\" /></IsNotNull></And></Where>";

query.ViewFieldsOnly = true;

try
{
    SPList list = contentDb.Sites[0].RootWeb.Lists["IOF"];

    foreach (SPItem item in list.GetItems(query))
    {
    valSection = new SPFieldLookupValue(item["Section"].ToString());
    items.Add(new Engagement(valSection.LookupValue, item["FileRef"].ToString().Replace(@"/IOF/", ""), path + item["FileRef"].ToString()));
    }
}
share|improve this question
    
Is there a reason you're opening the site via the content database like that and not using (SPSite oSiteCollection = new SPSite("Absolute_URL")? –  lgaud Aug 22 '13 at 14:40
    
I actually had the SPSite() way first. But that caused the same behavior, so I switched it to use the method shown above, which seems to be the way when using timer jobs. –  NYTom Aug 22 '13 at 14:50

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.