Wednesday, March 9, 2011

The server could not complete your request SharePoint designer 2010

Here is a common problem often faced while opening a SharePoint Site in SharePoint Designer 2010:”the server could not complete your request SharePoint designer 2010”. If you click the Details button it will open a dialog box; however, it is almost always empty..

If you are face this problem, check the Event viewer for the following error: “The extended protection settings on IIS do not match the settings configured on the transport”. If this error appears, follow the steps below:

  • Open IIS Manager (Click Run in start menu and then type INETMGR)
  • Find the desired site in IIS Manager
  • Open “Authentication” from body panel
  • Select Windows Authentication
  • Click “Advance Settings…” in the right panel
  • Select “Off” from the extended protection dropdown box
  • Select the check box for Enable Kernel-Mode authentication
  • Click Ok.
  • Reset your IIS

You are done. eNjoy...

Maintain Session in SharePoint Web Part Development

Ok friends, sometimes when you are developing a web part for SharePoint and are trying to maintain Session state, you might run into the following error message ……………………………..”Object reference not set to an instance of an object.” If you are new to SharePoint or have never seen this error before you are probably wondering, now what do I do? The solution is very simple

To resolve this issue you have to follow the steps mentioned below.

Step 1:

  • Open web.config for the current SharePoint Site, default location is

C:\Inetput\wwwroor\wss\VirtualDirectories\ < your sharepoint site port number >

  • Find < httpModules > tag in web.config file
  • Add the text between opening and closing tag shown below.

< add name = "Session" type = "System.Web.SessionState.SessionStateModule">

Step 2:

  • Open IIS Manager (Click Run in start menu and then type INETMGR)
  • Find the desired site in IIS Manager
  • In the body panel find “Modules” and double click this.
  • On the right hand panel, click “Add Managed Module...
  • In the name text box, enter the appropriate name for your session i.e. “SessionState”
  • Select “System.Web.SessionState.SessionStateModule, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” from type dropdown.
  • Click Ok.

Now, you should be good to go. eNjoy

Friday, January 28, 2011

Concatenate multiple row values in one string

Objective:
Here is another one. Suppose you have one table with two columns, ID & Name. However, you need to select values from the Name column and separate the values with a comma like this:
Name1, Name2, Name3…

Here is an example:

You have table with two fields:


You want the result set to look like the following:

Solution:
The solution is very simple, as is always :)
  1. Create one User Defined Function (UDF) that will accept the comma separated ID and return the comma separated name.


CREATE FUNCTION Func_GetNameFromCommaSepId(

@Id VARCHAR(MAX)

)

RETURNS NVARCHAR(MAX)

AS

BEGIN


DECLARE @Name NVARCHAR(MAX)


SELECT @Name = COALESCE(@Name+ ', ', '')+ Name From tblMaster where Convert(varchar(5),Id) in(Select DataItem From dbo.Func_SplitString(@ID,','))

RETURN @Name

END

  1. Now use this UDF as your query.

select dbo.Func_GetNameFromCommaSepId('1,2,3,4,5,6,7')as Name


Your result set will look like this:

Split String in SQL Server UDF with custom delimiter

Objective:
Ok friends, suppose you are writing a stored procedure and you have no idea how many parameter values to pass to it. Now what to do?

Solution:
There are a few options you can try here. The first option, you can write an iterative procedure that calls the stored procedure several times; however, this option makes unnecessary calls to your stored procedure and reduces the performance of the application. Alternatively, you can pass one single string to the stored procedure with a delimiter and split the string inside the stored procedure. This will give you a result set in tabular format providing fewer stored procedure calls and better performance that the first option.

Here I am going to show you how to pass a string and get the result set.
  1. Create one User Defined Function (UDF) that accepts two parameters
    1. StringToSplit – String you want to split
    2. DelimiterToSplit – Delimiter

The function will return one table that includes a column called “DataItem”.


CREATE FUNCTION Func_SplitString(

@StringToSplit VARCHAR(MAX),

@DelimiterToSplit VARCHAR(5) = ','

) RETURNS @ReturnList TABLE (DataItem VARCHAR(100))


BEGIN

DECLARE @sItem VARCHAR(8000)

WHILE CHARINDEX(@DelimiterToSplit,@StringToSplit,0) <> 0

BEGIN

SELECT @sItem=RTRIM(LTRIM(SUBSTRING(@StringToSplit,1,CHARINDEX(@DelimiterToSplit,@StringToSplit,0)-1))),

@StringToSplit=RTRIM(LTRIM(SUBSTRING(@StringToSplit,CHARINDEX(@DelimiterToSplit,@StringToSplit,0)+LEN(@DelimiterToSplit),LEN(@StringToSplit))))

IF LEN(@sItem) > 0

INSERT INTO @ReturnList SELECT Replace(@sItem,'''','')

END


IF LEN(@StringToSplit) > 0

INSERT INTO @ReturnList SELECT Replace(@StringToSplit,'''','')

RETURN

END

  1. Now, you have several options available for using this UDF
    1. In T-SQL -

select * from dbo.Func_SplitString('sujeet#kumar#Richmond#Virgina#23060#USA','#')



    1. In the Stored Procedure -

CREATE Procedure Proc_AddEdit_GroupMaster

@GroupName VARCHAR (MAX)

AS

BEGIN


Declare @NewGroupName AS Varchar(MAX)

SET @NewGroupName = REPLACE(@GroupName,'"','''')

--Insert Return value from Func_SplitString to tblGroupMaster

Insert into tblGroupMaster

(GroupName) (Select DataItem From dbo.Func_SplitString(@NewGroupName,','))

END


Now, all you need to do is to determine the best way to use the UDF in your application.
Note: There are a few limitations with this solution. For homework, try to see if you can locate these. :)