Posts Tagged ‘SharePoint 2007’

Defragging WSS 3.0 and SharePoint 2007 to manage SharePoint performance

Tuesday, January 12th, 2010

This article will illustrate how a SharePoint database can be fragmented for optimisation which can be applied to either versions of SharePoint: WSS 3.0 or SharePoint 2007.   

Before running the script it is important to consider the stability of the system and monitoring the performance and evaluation event logs to ensure the result of running this process is not going to potentially harm your SharePoint environment.

We recommend that you do not alter this script in any way since it could potentially cause an issue to your SharePoint database.

The suggestion from Microsoft is to shut-down your running instance of SharePoint so the database can be completely fragmented, since any locked pages will be ignored in the script.

The recommendation is that you execute this query weekly, monthly, whenever required depending on your environment.

Here is the script to fragment your SQL Server database, to enable this script please complete the following steps:

Step 1: Open SQL Server Management Studio

Step 2: Connect to the SharePoint instance SQL Server

Step 3:  Paste the following script into a new SQL Windows

Step 4:  Execute the script

Step 5: Create a New Query and type the following command: “exec [dbo].[proc_DefragmentIndices]”

CREATE PROCEDURE [dbo].[proc_DefragmentIndices]

AS

    SET NOCOUNT ON

    DECLARE @objectid int

    DECLARE @indexid int

    DECLARE @command varchar(8000)

    DECLARE @baseCommand varchar(8000)

    DECLARE @schemaname sysname

    DECLARE @objectname sysname

    DECLARE @indexname sysname

    DECLARE @currentDdbId int

    SELECT @currentDdbId = DB_ID()

    PRINT CONVERT(nvarchar, GETDATE(), 126) + ‘: Starting’

    — Loop over each of the indices

    DECLARE indexesToDefrag CURSOR FOR

    SELECT

        i.object_id,

        i.index_id,

        i.name

    FROM

        sys.indexes AS i

    INNER JOIN

        sys.objects AS o

    ON

        i.object_id = o.object_id

    WHERE

        i.index_id > 0 AND

        o.type = ‘U’

    OPEN indexesToDefrag

    — Loop through the partitions.

    FETCH NEXT

    FROM

        indexesToDefrag

    INTO

        @objectid,

        @indexid,

        @indexname

    WHILE @@FETCH_STATUS = 0

    BEGIN

        — Lookup the name of the index

        SELECT

            @schemaname = s.name

        FROM

            sys.objects AS o

        JOIN

            sys.schemas AS s

        ON

            s.schema_id = o.schema_id

        WHERE

            o.object_id = @objectid

        PRINT CONVERT(nvarchar, GETDATE(), 126) + ‘: ‘ + @schemaname + ‘.’ + @indexname + ‘ is now being rebuilt.’

        — Fragmentation is bad enough that it will be more efficient to rebuild the index

        SELECT @baseCommand =

            ‘ ALTER INDEX ‘ +

                @indexname +

            ‘ ON ‘ +

                @schemaname + ‘.’ + object_name(@objectid) +

            ‘ REBUILD WITH (FILLFACTOR = 80, ONLINE = ‘

        — Use dynamic sql so this compiles in SQL 2000

        SELECT @command =

            ‘ BEGIN TRY ‘ +

               @baseCommand + ‘ON) ‘ +

            ‘ END TRY ‘ +

            ‘ BEGIN CATCH ‘ +

               — Indices with image-like columns can’t be rebuild online, so go offline

               @baseCommand + ‘OFF) ‘ +

            ‘ END CATCH ‘

        PRINT CONVERT(nvarchar, GETDATE(), 126) + ‘: Rebuilding’

        EXEC (@command)

        PRINT CONVERT(nvarchar, GETDATE(), 126) + ‘: Done’

        FETCH NEXT FROM indexesToDefrag INTO @objectid, @indexid, @indexname

    END

    CLOSE indexesToDefrag

    DEALLOCATE indexesToDefrag

    RETURN 0

GO

For advice how to configure or maintain SharePoint deployment instance please contact Click IT Solutions.  We have specialised consultants who have experience with development, configuring and maintaining an instance of SharePoint.  We can assist with performance tuning, infrastructure planning and extending the scalability of the SharePoint application.  You can contact Click IT Solutions at (02)  9029 5194 or alternatively email us at info@clickitsolutions.com.au.

How to write custom List Filter Queries in Webparts using SharePoint Office Server 2007, WSS 3.0

Tuesday, December 22nd, 2009

One of the problems users experience using SharePoint WSS 3.0 or even SharePoint Office Server 2007 out of the box is the lack of support to perform filter queries on items in a list.   This article shows you how you can use Visual Studio to create a custom webparts which can perform Filter Queries on SharePoint lists.   This functionality with Webparts is supported in either SharePoint 2007 or WSS 3.0.   The other advantage with writing your own filtered webpart is you have the ability to optimise your query to perform these search queries efficiently and reduce any bottleneck in your SharePoint application.  Today we are going to be using the SharePoint API to perform queries across lists and being able to return this data into a view.

Pre-requisites

Before you start it is important that you have a copy of either Visual Studio 2005 or 2008 with the following extension Visual Studio extensions for SharePoint version 1.2.  Once you have downloaded this and installed this extension you are ready to commence this tutorial and create the following webpart.

Start Developing Custom Webpart with Visual Studio

Now we can start to develop this webpart using Visual Studio, so this is a quick guide to creating a webpart and deploying this onto your web-server.

Step 1: Open Visual Studio

Step 2: Create a new Project -> Visual C# -> SharePoint -> Web Part

Step 3: Name this Web Part whatever you desire

Step 4: Select FULL TRUST (Deploy to GAC) on the dialog box “Select Trust Level”

Step 5: Now open up Webpart1.cs file and inside you should see a section of code resembling the following:

using System;

using System.Runtime.InteropServices;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Serialization;

 

using Microsoft.SharePoint;

using Microsoft.SharePoint.WebControls;

using Microsoft.SharePoint.WebPartPages;

 

namespace TestWebpart

{

[Guid("876ffbbe-6196-47d4-b77a-12b69c07be45")]

public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart

{

public WebPart1()

{

}

 

protected override void CreateChildControls()

{

base.CreateChildControls();

 

// TODO: add custom rendering code here.

// Label label = new Label();

// label.Text = “Hello World”;

// this.Controls.Add(label);

}

}

}

Step 6: We are going to use the following object inside our code “ListViewByQuery”.  The will provide the output for our query as this is a SharePoint component which will render a list view which will resemble what we see inside SharePoint.

Now add this “ListViewByQuery” into the following section of code:

protected override void CreateChildControls()

{

base.CreateChildControls();

ListViewByQuery view = new ListViewByQuery();

this.Controls.Add(view);

}

Step 7: Now we need to include the query which is what performs the lookup of your SharePoint list to retrieve the relevant data.  The following line of code is required to perform this:

query = new SPQuery(list.DefaultView);

query.ViewFields = “<FieldRef Name=’Created’/><FieldRef Name=’LinkTitleNoMenu’/><FieldRef Name=’FirstName’/><FieldRef Name=’Current_x0020_Company’/><FieldRef Name=’Community_x0020_Group’/><FieldRef Name=’Skill_x0020_1′/><FieldRef Name=’Skill_x0020_2′/><FieldRef Name=’Skill_x0020_3′/>”;

query.Query = “<Where></Where><Orderby><FieldRef Name=’Created’ Ascending=’false’ /></OrderBy>”;

query.RecurrenceOrderBy = true;

The “ViewFields” is used to assign the columns to be displayed inside the list view on your rendered SharePoint webpart.  It is a requirement that you supply some values here otherwise you will find that your webpart will not execute inside your SharePoint site.

A typical value you might provide for your “ViewFields” would be:

Query.ViewFields = “<FieldRefName=’Created’/><FiedRefName=’LinkTitleNoMenu’/>”

This would display a list consisting of two columns which will display a hyperlink title to display the List details and Created will display the date when the list item was created.

Now the Query string provides you with the flexibility to define your own query on what list items you want retrieved.   Collaborative Application Markup Language (CAML) is an XML based query language which is used here to help you build custom SQL like queries to run on SharePoint Lists. There is a utility written which can assist you with writing a query.  I suggest you download the following utility CAML Query Builder for SharePoint 2003 and SharePoint 2007.

Here is a sample CAML query for searching data on a Customer List:

<WHERE>

<CONTAINS>

<FIELDREF NAM=’Title’ /><VALUE TYPE=’TEXT’>John</VALUE>

</CONTAINS>

</WHERE>

Step 8: Putting it all together

Now is the time to finally put this off these components inside the webpart together so it can perform the filtered search correctly.  Below is the required code for you to build your Custom Filtered Webpart to be compiled in Visual Studio:

public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart

{

public WebPart1()

{

}

protected override void CreateChildControls()

{

base.CreateChildControls();

ListViewByQuery view = new ListViewByQuery();

SPWeb currentweb = SPContext.Current.Web;

SPList list = currentweb.Lists["Customers"];

view.List = list;

SPQuery query = new SPQuery(list.DefaultView);

query.ViewFields = “<FieldRef Name=’Created’/><FieldRef Name=’LinkTitleNoMenu’/>”;

query.Query = “<Where><CONTAINS>

<FIELDREF NAM=’Title’ /><VALUE TYPE=’TEXT’>John</VALUE>

</CONTAINS>

</Where><Orderby><FieldRef Name=’Created’ Ascending=’false’ /></OrderBy>”;

query.RecurrenceOrderBy = true;

view.Query = query;

this.Controls.Add(view);

}

}

So this is a quick reference of how you can build a Filtered Web Part in SharePoint which used a ListViewByQuery component to render the searched contents into a SharePoint list view.   The SPQuery class is used to perform a CAML XML based query to extract the specific List Items from the desired SharePoint List you have selected.

This custom webpart can be included in either Windows SharePoint Services 3.0 (WSS 3.0) or SharePoint Office Server 2007.

 At Click IT Solutions we specialise in developing custom Web Parts for SharePoint.  If you would like to customise your SharePoint portal contact us to speak with a consultant who can provide advice regarding this.  You can contact us at (02) 9029 5194 or alternatively email us at info@clickitsolutions.com.au.

SharePoint Performance – How to optimise a SharePoint 2007 Farm

Tuesday, December 22nd, 2009

This article will discuss performance issues affecting SharePoint 2007 or WSS 3.0 and what you can do to ensure that your setup is optimised according to the recommendations suggested by Microsoft for setting up a typical SharePoint farm.   There are quite a number of factors which need to be considered when optimising SharePoint’s performance.  Microsoft has produced additional resources which you can learn many new skills and this can be found here.

The recommendation for configuring SharePoint is to configure a farm consisting of 2 servers one server for the web-front end and another server for the database.  We would suggest that you have 64bit hardware and Windows 2008 operating systems.  Especially for the web-front end using Windows 2008 will give you best performance when you configure IIS 7 caching to optimise the performance of loading your site content.   Using IIS 7 as the underlying structure for running the website will give you much better performance using the enhanced operating system.   It is also important to ensure not to put too much network distance between these two servers.  The recommendation is too ensure that the web-front end server doesn’t have more than 1ms network latency too the database server.

Another issue of important is for you to ensure that your SharePoint lists do not exceed 2000 items.  If any of your lists do contain items with more than 2000 items the suggestion would be to split these list items into folders so that each folder contains no more than 2000 items.   You can run a data-fix to iterate through all the list items in the list and generate a folder then physically move these list-items into the folder you generated.

The final suggestion is to ensure that all queries performed on lists throughout your SharePoint portal are completely optimised.  The recommendation is the use of views to reduce the amount of data retrieved from lists and even making your queries more intelligent.   Writing customised queries inside of Webparts to extract data from a particular folder inside a list will limit the number of items sequentially searched each time and will ensure that your SharePoint site performs quicker.

This is just a brief overview about what you can do with SharePoint to modify your environment to ensure the application performs as quickly as possible.   If you would like to find out more information about how Click IT Solutions can assist you with your existing SharePoint solution and help to optimise this for you please contact us at (02) 9029 5194 to speak with one of our consultants.  We have experience with performing upgrades, making modifications to the application, database changes and server deployment changes to ensure that you SharePoint system always efficiently optimised.   You can also reach us via email at info@clickitsolutions.com.au.