Selecting missing ranges in SQLserver

So it’s a long time since I wrote any SQL scripts, but I needed to be able to select a set of depth ranges not covered by a table.  Lets say I have a table of rules:

Start |  End  | Rule
3            4          xxx
10         11          yyy

So what I want to see is the depths for which no rule is defined:

Start | End
0          3
4         10
11        null

So here it is:

DECLARE @MissingRanges TABLE (startDepth float, endDepth float);

-- Build a table of the missing data ranges that are between the defined rules
-- For each rule take the start depth of a rule as the end depth for a missing data range
INSERT INTO @MissingRanges(endDepth)
SELECT r1.StartDepth
FROM Rule r1;

-- Now we have the end depth for the missing ranges, find the defined rule with an end
 depth immediately below that, or start from zero.  Use a correlated subquery
UPDATE miss Set startDepth = COALESCE((Select Max(EndDepth)
FROM Rule r1
WHERE r1.EndDepth < miss.endDepth),0)
FROM @MissingRanges miss;

-- Add a last missing range below the deepest defined end depth
INSERT INTO @MissingRanges(startDepth)
FROM Rule r1;

Posted in Computers and Internet, SQL | Leave a comment

Web part maintenance page

Just discovered a good tip, how to get to the SharePoint web part mainteneance page when it decides not to offer you a link: add ?contents=1 to the URL.  Thanks to


Posted in Uncategorized | Leave a comment

Moving changes to a branch in tfs

I developed some code under the main root, then it bacame necessary to move the development into a branch so I could work on it with other people.   I created a shelve set but then had to work out how to get my changes into the new branch without checking into the main and upsetting the rest of the team.

The solution is to use tfs power tools from the command line.  First cd to the top level folder where the new branch is mapped.  Then given a shelveset  from the main branch called RoleImplementation1, enter the command:

C:\Work\CasePoint\Branches\Roles>tfpt unshelve “RoleImplementation1” /migrate /source:$/CasePoint/Development /target:$/CasePoint/Branches/Roles

Posted in Uncategorized | Leave a comment

Hello world!

Welcome to This is your first post. Edit or delete it and start blogging!

Posted in Uncategorized | 1 Comment

Enum evaluation

A method to evaluate an enum

private T ValidateEnum<T>(string value, T defaulValue) where T:struct, IConvertible
    if (!typeof(T).IsEnum)
        throw new ArgumentException("T must be an enumerated type");

    if (string.IsNullOrEmpty(value))
return defaulValue;

    if (Enum.IsDefined(typeof(T), value))
return (T)Enum.Parse(typeof(T), value);
        return defaulValue;

Posted in Computers and Internet | Leave a comment

Sharepoint Code Access Security / WSP Builder glitch

WSP deployment will automatically add permission sets to the trust file but it will not add the necessary classes.
The trust file is identified by the entry in web.config:
   <trust level="WSS_Custom" originUrl="" />
This in turn references the security policy entry:
      <trustLevel name="WSS_Medium" policyFile="c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\config\wss_mediumtrust.config" />
      <trustLevel name="WSS_Minimal" policyFile="c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\config\wss_minimaltrust.config" />
      <trustLevel name="WSS_Custom" policyFile="c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\config\wss_custom_wss_minimaltrust.config" />
The file wss_custom_wss_minimaltrust.config (or similar with a guid) is created as a copy of the initial trust file before wsp deployment eg wss_minimaltrust.config.  Modifications specified in manifest.xml are added by the wsp deployment.
The correct permission sets are being added to the new config file eg:
            <PermissionSet class="NamedPermissionSet" version="1" Description="WSPBuilder generated permissionSet" Name="pds.casepoint.wsp-90151428-79ca-47fc-a07d-b65c436390d4-10">
              <IPermission class="AspNetHostingPermission" version="1" Level="Medium" />
              <IPermission class="SecurityPermission" version="1" Flags="Assertion, Execution, ControlThread, ControlPrincipal, RemotingConfiguration" />
              <IPermission class="SharePointPermission" version="1" ObjectModel="True" />

However it does not add new SecurityClasses entries to the start of the config file, so while it may look like youor assembly has SharePointPermission, it wont have without an entry like this:
            <SecurityClass Name="SharePointPermission" Description="Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
I simply copied all the security classes from the medium trust file into the minimal trust file (I dont think it’s a security risk to declare the classes if they are not used)
Posted in Computers and Internet | Leave a comment

Cant remove web.config entries

Trying to manually remove entries from a sharepoint site’s web.config and they reappear when I install a new feature.
They appear to be active web.config modificatios from an old solution that sharepoint still thinks is active, even though the old solution is no longer deployed or in the solution store.
 for this file
Add it to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\ADMIN as the man says and access it by http://<your sp server>:<your spadmin PortNumber>/_admin/webconfig.aspx
Posted in Computers and Internet | Leave a comment

Running .net 2 dll on team build server 2010

Kept getting an error from the constructor of my custom build activity.  This occured when a reference was added to cablib.dll.  After extensive trouble to find the error (I added a static constructor to my class, and created an instance in that, as the actual constructor was auto generated from the XAML) I got a real stack trace which said it cant create the mixed mode dll.
Garry found the solution:

To run a custom activity that references cablib.dll or similar, which is a 2.1 assembly you need to add a file:

C:\Program Files\Microsoft Team Foundation Server 2010\Tools\TFSBuildServiceHost.exe.config
with the following contents:
<?xml version="1.0" encoding="utf-8" ?> 
  <startup useLegacyV2RuntimeActivationPolicy="true"> 
            <supportedRuntime version="v4.0" />    
restart the build service and it should run OK
Posted in Uncategorized | Leave a comment

Sharepoint error messages

After getting very frustrated with sharepoint "Unknown Error" I thank google for helping me find this (here):

To get a stack trace instaead of the usual error message, modify the web.config (in C:\inetpub\wwwroot\wss\VirtualDirectories\<port>)

Change <SafeMode … CallStack="false" …> to <SafeMode … CallStack="true"…>

Change <customErrors mode="On" /> to <customErrors mode="Off" />

Change <compilation batch="false" debug="false"> to <compilation batch="true" debug="true">

Posted in Uncategorized | Leave a comment

I am not a system account

Couldn’t get sharepoint to stop listing me as system account and not as my logged in user.  This did the trick:

stsadm -o updatefarmcredentials -identitytype NetworkService


iisrest /noforce

just dont ask whyConfused (

p.s. Having done this I started getting    VSeWSS Service Error: Access Denied

when I deployed from visual studio.  So I created a new app pool for the VSeWSS site and ran that under an account in the local administrators group, changed the site to use that app pool, did an iisreset, scattered some chicken bones, and lo.

Posted in Uncategorized | Leave a comment