Monthly Archives: March 2013

Querying Large Lists using CAML

Struggling with this one for a large point of the day, before I realised what was happening.  I was running a query using SPQuery and CAML against a list that needed to be restricted for a subset of users.  I was happily running it as me, but my test (restricted) user was getting Null reference errors.

I quickly realised that my list had over 36,000 items in it (split into folders of < 2000 items) so I had to come up with a way of running the same CAML query over the list independent of user.

There are number of options (well explained by <this excellent blog entry by Steve Peschka to deal with list thresholds and programmatic overrides.

SPList has an EnableThrottling property, which is set to True by default.  You can use the Object Model to set it to False temporarily.  The problem is that the permissions to do so cannot be done by anyone who isn’t a Farm Administrator.  SPSecurity.RunWithExecutivePrivileges run as the Application Pool account which is, unless you’ve configured something wrongly should not be a Farm Admin level account.

To cut a long story short, you need to either do this in code or Powershell when the list is created.  Alternatively, if your list has popped over the item count threshold, you can do it at any time.  The Powershell script is simple.

$url="<%YOUR URL HERE%>"
$listname="<%YOUR LIST NAME HERE%>"
$web = Get-SPWeb $url
$list = $web.Lists[$listname]
$list.EnableThrottling = $false
$list.Update()

To switch throttling back on, simply re-run the script, changing the $false to $true.

The beauty of this is that it applies on a list by list basis, so you don’t have to go into Central Administration and make Web Application wide changes to get a single large list to query.  The script is modified from one published by Dina Ayoub.

Disallowed Updates on creating a Web Application

Hit an unusual one when creating Web Applications on a Farm.  Despite having gone through the process without any problems on two other farms, one particular (existing) setup fell over on every single Web Application I tried to create.  It manifested itself in an IE unable to connect to server error, but when you go into General Settings the following error is shown.

unsafeupdates

Not entirely sure what the cause is, but the fix is quite simple.

Log onto the Central Admin machine using Remote Desktop Connection, open a SharePoint 2010 Management Shell and run the following script:

$w=GetSPWebApplication <%WEBAPPURL%>
$w.HttpThrottleSettings

$w.Update()

You can now go into General Settings and carry on as normal.