Pages

Thursday, May 5, 2011

SharePoint 2010 Debugging

This one always gets me… There’s a few things that need to be done in order to better debug SharePoint.

  • Custom Errors Off
  • Enable Call Stack Trace
  • Debugging Mode
  • ASP.Net Tracing

…and the big one.

  • Multiple web.config files.

OK, to break it down. First, know what Web Application you want to debug. This might sound silly but I’ve been caught out a few times with a couple of (not straight forward) sp farm setups.

SharePoint web.config files

Make sure you are looking at the right Virtual Directory. Also, as mentioned as the last bullet, there are multiple web.config files that might need modifying. Below is a scrape from a good article by Daniel on blogspot (thanks)

The web.config files are genearally found in the following locations:

  • web.config file in the root folder of each virtual server / IIS Application.

Local_Drive:\Inetpub\wwwroot
This is the usually the file that contains most of the web configuration of a SharePoint site collection. To display full errors you would need to modify this web.config file. There may be one for each of the SharePoint applications running in some cases (MySites, Multiple Portals or Instances of SharePoint, Central Admin, etc.). If this is the case, you will only need to modify the web.config file which is in the root of the virtual directory for the instance of SharePoint which you using. To find out which directory is used by various SharePoint applications/websites, view the properties of the SharePoint website in IIS and from the "Home Directory" tab, the value in the "Local path" field will take you to the directory where the web.config file is for the specific instance of SharePoint / Application in IIS.

  • web.config file used in Web Part resources for the Global Assembly Cache (GAC)

Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\wpresources

  • web.config configuration file(s) for extending other virtual servers

Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\CONFIG

  • web.config file which defines configuration settings for the /_vti_bin virtual directory

Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\ISAPI

  • web.config file which defines configuration settings for the /_layouts virtual directory

Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\LAYOUTS

  • web.config configuration file for Central Administration pages.

Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\ADMIN\Locale_ID

Now that you know what config files to modify, here are the key parts that need modification.

Custom Errors Off

Set the customErrors mode to "Off"
Find:
<system.web> ...
<customErrors mode="On" />
Change To:
<system.web> ...
<customErrors mode="Off" />

Enable Call Stack Trace

Set the CallStack value of the SafeMode element to "true"
Find:
<SharePoint>
<SafeMode ... CallStack="false" ... >
<SharePoint>

Change To:
<SharePoint>
<SafeMode ... CallStack="true" ... >
</SharePoint>

Debugging Mode

Set batch and debug to "true"
Find:
<compilation batch="false" debug="false">
Change To:
<compilation batch="true" debug="true">

ASP.Net Tracing

Include the following line in the <system.web> element of the web.config file.
<system.web> ...
<trace enabled="true" pageOutput="true"/>

And that’s about that. I will post a bit about debugging via log files soon.

Friday, April 29, 2011

SharePoint 2010 - User Profile Sync Issues

Tricky topic, heaps of articles out there, but...

Make sure that both FIM services are started before worrying about any user profile sync issues.

For instance, in the contoso VHD, I added new AD users but they would not sync. When viewing the Sync Connection, there wasn't any. So I tried creating a new one but there were drama's with this which led me to the solution, Make sure the FIM services are running. As soon as these services are running, the sync connection will be displayed in CA.

Thursday, April 29, 2010

Using ROW_NUMBER

ROW_NUMBER() OVER (PARTITION BY ORDER BY ) AS RowNum

Monday, September 29, 2008

Deleting a user from all db's

If you need to recursively remove a user from all db's, run this.
What happens is the statement first checks whether the user is in the 'current' database (remember
msforeachdb)
then, changes the current context to the database, executes the dropuser command, then prints that it did it.

DECLARE @usr sysname

DECLARE @passwd varchar(20)
SET @usr = 'AUser'
SET @passwd = 'password'


DECLARE @cmd1 nvarchar(2000)
SET @cmd1 = 'if exists (select name from ?.dbo.sysusers where upper(name) = '''+@usr+''') '+
'begin '+
'use ? '+
'exec sp_dropuser ''' +@usr+ ''''+
'print ''dropped user from ?'''+
'end'
exec sp_msforeachdb @cmd1

Monday, August 11, 2008

Using a CSV array as a filter in a Stored Procedure

Here's a really handy trick I picked up.
If you have a stored procedure and you would like to pass a set of values in as part of a filter, ie. A list of Identifiers, or Names that you want to filter on, then you can use a handy table that contains just a bunch of numbers. I'll show you.

-- Create the table
CREATE TABLE [dbo].[Nums](
[n] [int] NOT NULL,
PRIMARY KEY CLUSTERED
(
[n] ASC
) ON [PRIMARY]
) ON [PRIMARY]

-- Now add the numbers
DECLARE @index int
SET @index = 1
WHILE (@index < @NumbersToAdd)
BEGIN
INSERT INTO [dbo].[Nums] (n)
VALUES (@index)
SET @index = @index +1
END

create a function to put the values into a table.

CREATE FUNCTION dbo.ufn_CommaValues(@List varchar(8000))
RETURNS @Array Table
(
pos integer,
val varchar(10)
)
AS
BEGIN
INSERT @Array
SELECT
n - LEN(REPLACE(LEFT(@arr, n), ',', '')) + 1 AS pos,
CAST(SUBSTRING(@arr, n, CHARINDEX(',', @arr + ',', n) - n) AS INT) AS val
FROM Nums --Uses the Nums table.
WHERE n <= LEN(@arr)
AND SUBSTRING(',' + @arr, n, 1) = ','
ORDER BY pos
RETURN
END

Now we have everything you can use it like this:

CREATE PROC dbo.usp_Example
@List varchar(8000) --This is a list of comma separated GUIDS
AS
SELECT *
FROM TableA
INNER JOIN dbo.ufn_CommaValues(@List) CSV ON TableA.Id = CSV.Val


Pretty useful if you have a list of records that you want to filter on, particularly for debugging.