Lesson on SPSiteDataQuery

Today I learned a hard lesson.  A single letter was causing a big problem for me: “The query cannot be completed because the number of lists in the query exceeded the allowable limit. For better results, limit the scope of the query to the current site or list or use a custom column index to help reduce the number of lists.” This was more frustrating to me when I see this Microsoft artical http://support.microsoft.com/kb/935502

Since they have suggested to do

“limit the scope of the query to the current site or list or use a custom column index to help reduce the number of lists”

Later I came to know about MaxListLimit, which is really oxygen supply for this error.

MaxListsLimit vs MaxListLimit

After a while of researching, I found out that the original example that I had been using for the basis of my SPSiteDataQuery had used MaxListsLimit where MaxListLimit should have been for the Lists property of my SPSiteDataQueryI was using

“<Lists BaseType=’1′ MaxListsLimit=’0’/>”

When what I needed was just:

“<Lists BaseType=’1′ MaxListLimit=’0’/>”

This made the error go away as it let me search all of the lists in the entire site.  Not specifying a MaxListLimit would only search 1000 lists, but seems to throw an error if there are more than 1000 lists, instead of just searching the first 1000 that it finds.  I would recommend always using ‘0’ if you are not sure that the client will have less than 1000 lists.