Wednesday, January 11, 2012

Sandbox Solutions in SharePoint 2010 – Part 3

In this post we are going to see how resources count in sandbox solution. If you have not gone through part-1and Part-2 of this series, I would recommend you reading it first and then continue reading from here on.

Let us change the code that we had written in earlier post. This time we will write something which will utilize the resources and hence we get some bar increment in resources area in solutions.

Default resource quota allotted is 300 and we can change that using PowerShell or through central administration.

Let us do this with PowerShell as it is the easiest option. Open Powershell module from administrative tools.

Replace the URL of your site collection.

You need to be a farm administrator of course to perform all these operations.

So now if you come back and check the resource quota allocation then you should see it has dipped from 300 to 100.

Now let us add a code to our existing solution which will consume resources.

public class SandBoxWebPart : WebPart
        protected override void CreateChildControls()
                Label lbl = new Label
                    Text = "Hello from sandbox",
                    ID = "lblSandBox",
                    ForeColor = System.Drawing.Color.Blue



        private void RunLoop()
            int i = 0;

            while (true)
                i += 1;

What we have done is we have placed a never ending function which keeps executing while true and hence some point of time it will exceed the run time environment threshold value and throw an error.

So let’s build the solution and then generate WSP and then upload to solution gallery. After deploying and activating this new WSP and coming back to home page where this web part is placed, here is what we get.

Because of infinite loop we get this error message, if we keep executing this code for number of times then we can see the change setting up on resource quota bar and usage increased in solution gallery.

Farm administrator can also block the solution if administrator found that particular solution is consuming many resources. Go to system settings, user code solutions.

Select wsp to block and click on block.

And this is what we get when we try to run our solution.

In next post we are going to explore visual studio experience and capability working on sandbox solutions. Read Part-4 for further reading.

No comments:

Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to