2

I found so many questions about list view threshold in SharePoint. As Microsoft recommend items should not exceed 5000 (configurable in central admin). So i tried a sample piece of code to check where this error is belong to.

first i written a console application to retrieve data based on some condition from a list containing 50000 items with the help of SPSecurity class.

Sample code:

SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (SPSite CurrentSite = new SPSite("http://spdev-2013:5000/"))
            {
                using (SPWeb CurrentWeb = CurrentSite.OpenWeb())
                {
                    // code for fetch data from list
                }
            }
        });

Secondly i created a sample project with one visual web part and same code is written there also.

Now i wonder why console application is giving proper data without any error but when i use a SharePoint page with visual web part it throws an exception stating that threshold limit.

i also checked the current user in the RunWithElevatedPrivileges method and in both case (console and visual web part) it shows spfarmacc account which is farm account.

Note: results i am retrieving only 50-100 that is based on some condition.

can any one give some explanation why the result are differ in both scenario.

  • In the Web context case, are you sure you use the elevated Web object to fetch results? – Evariste Dec 20 '15 at 11:43
  • i have used CurrentWeb.Lists.TryGetLists("listname") and that CurrentWeb is obtained within that using statement. – Ankur Dec 20 '15 at 14:49
  • how does the code of your query look like? – Gwny Dec 21 '15 at 11:33
0

In my case it was a problem with the query. I guess when you execute a console application it runs with your rights but if you run this inside sharepoint it runs in the App Pool Account. Because of that you need to add this to your query:

query.QueryThrottleMode = SPQueryThrottleOption.Override;

Explanation. https://samlman.wordpress.com/2015/02/28/working-with-large-lists-in-sharepoint-2010-list-throttling/

  • thanks but I have checked the identity in both case but current user is showing SPFarm acc in both case. BTW SPQueryThrottleOption.Override option is to override the threshold limit for particular query. – Ankur Dec 21 '15 at 15:49
  • Yes but if you don't do this, the query will always throw the treshold error. It doesn't matter which user you use. Take a look at the link I attachet. – Gwny Dec 22 '15 at 8:09
  • OK but in case of console application why it is working perfectly and not throwing any exception. that's what i m asking. – Ankur Dec 22 '15 at 16:21
  • because you execute this under different environment, not inside sharepoint (just guessing) – Gwny Dec 23 '15 at 11:11
  • No it's not the case. for general purpose we use console app for testing. actually because of this console app working i had argument with one interviewer and then i checked that in visual web part it is giving error but not in console app. – Ankur Dec 23 '15 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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