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

I am querying multiple task lists in a SharePoint site. I can retrieve the results until I set the Query property and specify the OrderBy clause. The detailed exception and code is pasted below. Appreciate any help

private void doTasks(SPWeb currentWeb, SPSiteDataQuery q)
    {

    q.Query =
         "<OrderBy>" +
         "   <FieldRef Name='Priority' />" +
         "   <FieldRef Name='DueDate' />" +
         "</OrderBy>";

    // Specify the view fields.
    q.ViewFields = "<FieldRef Name='Title' Type='Text'/>";
    q.ViewFields += "<FieldRef Name='AssignedTo' Type='User' Nullable='TRUE' />";
    q.ViewFields += "<FieldRef Name='PercentComplete' Type='Number' Nullable='TRUE'/>";
    results = currentWeb.GetSiteData(q);

    if (results.Rows.Count > 0)
    {
             //blah!
    }
}

[COMException (0x80020009): 0x80020009]
Microsoft.SharePoint.Library.SPRequestInternalClass.CrossListQuery(String bstrUrl, String bstrXmlWebs, String bstrXmlLists, String bstrXmlQuery, ISP2DSafeArrayWriter pCallback, Object& pvarColumns) +0
Microsoft.SharePoint.Library.SPRequest.CrossListQuery(String bstrUrl, String bstrXmlWebs, String bstrXmlLists, String bstrXmlQuery, ISP2DSafeArrayWriter pCallback, Object& pvarColumns) +174

[SPException]
Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx) +27428978
Microsoft.SharePoint.Library.SPRequest.CrossListQuery(String bstrUrl, String bstrXmlWebs, String bstrXmlLists, String bstrXmlQuery, ISP2DSafeArrayWriter pCallback, Object& pvarColumns) +27812419
Microsoft.SharePoint.SPWeb.GetSiteData(SPSiteDataQuery query) +521
StoraEnso.Collaboration.WebParts.SubSiteItemAggregator.SubSiteItemAggregator.doTasks(SPWeb currentWeb, SPSiteDataQuery q) +189
StoraEnso.Collaboration.WebParts.SubSiteItemAggregator.SubSiteItemAggregator.Render(HtmlTextWriter writer) +441
Microsoft.SharePoint.WebPartPages.SPChrome.RenderPartContents(HtmlTextWriter output, WebPart part) +43

[WebPartException]
Microsoft.SharePoint.WebPartPages.SPChrome.RenderPartContents(HtmlTextWriter output, WebPart part) +19826502
Microsoft.SharePoint.WebPartPages.SPChrome.RenderWebPart(HtmlTextWriter output, WebPart part) +64
Microsoft.SharePoint.WebPartPages.WebPartZone.RenderZoneCell(HtmlTextWriter output, Boolean bMoreParts, WebPart part) +1997
Microsoft.SharePoint.WebPartPages.WebPartZone.RenderWebParts(HtmlTextWriter output, ArrayList webParts) +508
Microsoft.SharePoint.WebPartPages.WebPartZone.Render(HtmlTextWriter output) +1000
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +42
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +253
System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +87 System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +53
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +42
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240 System.Web.UI.Page.Render(HtmlTextWriter writer) +38 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4240

share|improve this question
    
Is that the whole exception and call stack? I dont see your code in the callstack? –  Anders Rask Aug 28 '11 at 17:10
    
I have updated with complete exception details –  Falak Mahmood Aug 29 '11 at 14:42

1 Answer 1

up vote 2 down vote accepted

During the migration some page layouts were using the SPSiteDataQuery to query the ContentTypes across different webs to get the content. The code worked fine in SP2007 but in SP2010 it was throwing exception as mentioned below:

Solution

Make sure the field your using for the order by is included in the SPSiteDataQuery.ViewFields property. As simple as that!

share|improve this answer

Your Answer

 
discard

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

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