Free Training–MSDN Benefit for PluralSight Training “Starter Subscription”

For a limited time, all MSDN subscribers qualify for a free one-year “starter” subscription that contains 20 of the most popular Pluralsight courses. Request your activation code now. This offer will be available for redemption through December 11, 2012. This offer is not available to DreamSpark, WebsiteSpark, BizSpark or MPN MSDN subscribers.



There are some really good courses, though the starter pack is mostly beginner and intermediate level, if you’ve already shelled out the money for an MSDN subscription then a lot of these courses may be more of a review  I would recommend the following as good refresher courses, it is about 18 hours of material; And of course you can skip through sections that you’re already familiar with…



C# Fundamentals – Part 1

Scott Allen



Introduction to Visual Studio 2010 – Part 1

Kate Gregory



Introduction to Visual Studio 2010 – Part 2

Kate Gregory



ALM with Team Foundation Server 2010

John Brown



In addition there are courses on the new VS 2012, TFS 2012, Metro and Windows 8, Windows Phone 7 and Test First Development, because it’s always good to exercise your mind…



Training is available in English only and includes the following courses:


Agile Team Practices with Scrum David Starr Intermediate [03:45:04] 15-Apr-10
ALM for Developers with Visual Studio 2012 Benjamin Day Intermediate [04:31:04] 24-Sep-12
ALM with Team Foundation Server 2010 John Brown Intermediate [03:59:27] 26-Mar-12
ALM with TFS 2012 Fundamentals Benjamin Day Intermediate [05:34:17] 5-Sep-12
Building Windows 8 Metro Apps with C# and XAML Ian Griffiths Intermediate [04:45:21] 17-Oct-11
Building Windows 8 Metro Apps with C++ and XAML Kate Gregory Intermediate [03:33:32] 18-Oct-11
C# Fundamentals – Part 1 Scott Allen Beginner [06:17:48] 26-Mar-10
C++ Fundamentals Kate Gregory Beginner [07:03:40] 13-Sep-11
Continuous Integration James Kovacs Beginner [02:34:40] 10-Dec-10
Developing for Windows 7 Eric Burke Intermediate [03:57:36] 12-Jul-10
IntelliTrace Marcel de Vries Intermediate [05:30:04] 27-Sep-12
Introduction to .NET Debugging using Visual Studio 2010 Mario Hewardt Intermediate [03:40:54] 28-Mar-12
Introduction to Building Windows 8 Applications Wahlin , Papa Beginner [05:43:46] 10-Oct-12
Introduction to Visual Studio 2010 – Part 1 Kate Gregory Beginner [04:37:53] 4-Apr-11
Introduction to Visual Studio 2010 – Part 2 Kate Gregory Beginner [03:07:30] 16-May-11
Introduction to Visual Studio 2012 – Part 1 Kate Gregory Beginner [03:44:56] 11-Oct-12
Introduction to Windows 7 Development Kate Gregory Beginner [04:21:01] 5-May-10
Kanban Fundamentals Steve Smith Beginner [01:31:50] 13-Feb-12
Microsoft Fakes Fundamentals Cooper , Belcham Intermediate [01:56:26] 10-Oct-12
Solution Modeling with UML in Visual Studio 2010 Richard Seroter Intermediate [02:24:32] 10-May-11
Test First Development – Part 1 Starr , Allen Intermediate [03:33:45] 16-Nov-10
Test First Development – Part 2 David Starr Intermediate [02:44:28] 21-Feb-11
Web Application Performance and Scalability Testing Steve Smith Intermediate [03:19:41] 27-Jul-11
Windows Azure Diagnostics Niraj Bhatt Intermediate [03:18:49] 9-Mar-12
Windows Phone 7 Basics Adam Grocholski Beginner [02:53:20] 11-Dec-10

SharePoint 2010 – Change Web Application to use Different Application Pool

When optimizing your farm, one of the recommendations from Microsoft is to only have 10 application pools running on the server (

Limit Maximum value Limit type Notes

Application pools

10 per web server


The maximum number is determined by hardware capabilities.

This limit is dependent largely upon:

  • The amount of memory allocated to the web servers

  • The workload that the farm is serving, that is, the user base and the usage characteristics (a single highly active application pool can utilize 10 GB or more)

But, once you’ve created your web applications, your ability to change the application pool the web application is running under is quite limited. Not something that can be done in the Central Admin GUI in any case so it either takes very careful planning or a way to go back and change the application pools.  Luckily, it can be quite easily achieved through a simple PowerShell script.

Here is a basic.ps1 file I created to easily change the Application Pool of a particular Web Application, as some point I may turn it into a real commandlet:

# Name:        Set-WebApplicataionPool.ps1 
# Description: Change which application pool the web application is using           
# Usage:       SetWebApplicationPool -WebAppURL "<ApplicationURL>" -ApplicationPoolName "<ApplicationPoolName>"
# By:
# Define 2 parameters for this script 

    [string] $WebAppURL = "$(Read-Host 'WebApplication URL')", 
    [string] $ApplicationPoolName = "$(Read-Host 'ApplicationPool Name')" 

Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue

if ($WebAppURL -eq "") 
   "Usage:    SetWebApplicationPool -WebAppURL <ApplicationURL> -ApplicationPoolName <ApplicationPoolName>"

Function Main()
    $apppool = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.ApplicationPools | where {$_.Name -eq $ApplicationPoolName} 
    if ($apppool -eq $null){ 
        write-host -foreground red "The Application Pool $ApplicationPoolName does not exist!" 
    $webapp = get-spwebapplication -Identity $WebAppUrl 
    if ($webapp -eq $null){ 
        write-host -foreground red "The Web Application $WebAppUrl does not exist!" 
    $webapp.Applicationpool = $apppool 
    write-host -foreground green "$WebappURL Application Pool has been changed to $ApplicationPoolName" 


Pretty straight forward, only word of caution is of course don’t do this during production hours as the ProvisionGlobally() function will provision the Web application to all servers that are running the current object’s parent Web service.  In other words, there is a small service outage as among other things the web.config in the physical site directory will get rewritten which causes an application pool recycle (sort of self evident with this sort of change, but hey, at least you can’t say you weren’t warned).

EDIT: So, turns out if you reassign the web application to a generic application pool and delete the old application pools from the server, SharePoint is still expecting to see them and will throw a Health Analyzer alert if you delete them from the server since it is trying to check for them.  In order to remove unused application pools from the SharePoint configuration, please review: SharePoint 2010 – Application pools recycle when memory limits are exceeded (PART 2) where I show how to remove unused application pools from the ApplicationPools collection.

Entity Framework: Procedure or View with System.NullReferenceException

I was coding a feature that was using a view, it was working fine in development when I had some pretty strict controls over the datasets utilized, but when it got out in the wild it started acting up with the following exception:

Error: System.NullReferenceException: Object reference not set to an instance of an object.
at System.Data.EntityKey.AddHashValue(Int32 hashCode, Object keyValue)
at System.Data.EntityKey.GetHashCode()
at System.Collections.Generic.GenericEqualityComparer`1.GetHashCode(T obj)
at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
at System.Data.Objects.ObjectStateManager.TryGetEntityEntry(EntityKey key, EntityEntry& entry)
at System.Data.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)
at lambda_method(Closure , Shaper )
at System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
at System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()

After digging around for a bit, it turns out the view I was using when connected to live data was actually returning a null value for one of the fields that was marked in the EF as not null. 

The quick fix was to go into the view and change the returning data to not return a null value, but long term is to go into the code and change the field in the Entity Framework model which was marked as not null to NULLABLE and then putting in some parameter validation to handle the null values if they are returned.

SharePoint–SQL Query to Find All Pages With WebPartTypeId

I know that Microsoft says don’t query the databases directly, and that’s still a good practice for any application level code.  But just like in sometimes it’s a quick and dirty way of getting things done, especially when dealing with content database cleanup or when you only need to run the results once or twice to get the information you need.

I had an issue recently where a webpart was being deprecated, and as such we needed to remove it from several large site collections.  Problem was that as this was a Site Collection in the wild, with active users and admins whom have inserted this webpart all over the place, getting rid of the references seemed like it was going to be a slow and painful process.  Removing it from the WebApp and letting things break was not an option.  Now we could use PowerShell to run through all the webs and subwebs, gathering each page and loading up the WebParts collection to see if it’s in there, but in a live farm that gets expensive.

Instead, we can run a very simple SQL query against the content database looking for a specific WebPartTypeID, and then use the list generated to browse to each page and correctly either remove or substitute in a new webpart through the SharePoint UI (which would be Microsoft recommended).

Here is the T-SQL code:

CAST( D.DirName AS varchar) + '/' + CAST(D.LeafName as varchar) as PageURL, 
tp_ID As WebPartSK, 
FROM       dbo.Docs D WITH (nolock) 
INNER JOIN dbo.Webs W WITH (nolock) ON D.WebID = W.Id
INNER JOIN dbo.WebParts WP WITH (nolock) ON D.Id = WP.tp_PageUrlID
WHERE WP.tp_WebPartTypeId='<your web parts id>'

This code will give you a nice list of all the URLs of pages that contain a particular type of WebPartTypeID.  If you don’t know what a particular WebPartTypeID is, the easiest way to find out is to create a page and place the target WebPart on the page, then run the query filtering for just the PageURL of the page you just created.

Active Directory | Compacting the NTDS Database file NTDS.DIT

Recently my home server started reporting some errors with reading from the AD database file:

NTDS (612) NTDSA: A request to read from the file "C:\Windows\NTDS\ntds.dit" at offset 14368768 (0x0000000000db4000) for 8192 (0x00002000) bytes succeeded, but took an abnormally long time (25 seconds) to be serviced by the OS. In addition, 1 other I/O requests to this file have also taken an abnormally long time to be serviced since the last message regarding this problem was posted 3267 seconds ago. This problem is likely due to faulty hardware. Please contact your hardware vendor for further assistance diagnosing the problem.

Now, searching for the issue on the Internet seemed to just return a bunch of answers to check the disk, HDD is failing, etc.  All of which I knew was not to be true.  This wasn’t a hardware issue but something related to the way the system was working, so I decided to run a quick compact of the database and see if that cleared up the issue as compacting the AD DS database NTDS.DIT improves performance. Although the improvement varies depending on amount of changes to the database – at the very least I figured if it was bad sectors, a compact and copy would move the file to good sectors.

  1. Open the Services.msc panel and stop "Active Directory Domain Services" (also stops the services below)
    1. File Replication Service
    2. Kerberos Key Distribution Center
    3. Intersite Messaging
    4. DNS Server
  2. Open a command line, type the following (without quotes):
    1. “ntdsutil”
    2. “activate instance ntds”
      1. At this point, you should see the following:
      2. image
    3. “files”
    4. “compact to c:\temp”
      1. And now you should see a very poorly rendered ASCII graph showing that the compact was successful
      2. image
    5. At this point, enter “quit” twice.  Once to get out of file maintenance, the second to get out of the ntdsutil program
    6. Now, copy the ntds.dit file from temp over the file located in C:\windows\ntds\ntds.dit and delete all the *.log files
    7. Last step, start the "Active Directory Domain Services" in services.msc, the other dependant services that stopped will also come back up.

So, fingers crossed it all looks good.