Monday, May 20, 2013

Nice quote

“There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies.”

- C.A.R. Hoare

Friday, May 17, 2013

Specify a CDN fallback when using ASP.NET Web Optimizations

One of the recommendations to improve your web application performance is to use a CDN(Content Delivery Network). This allows you to load common files(like for example jQuery) from the CDN server instead of your own. Extra advantage is that if the user already loaded the same script for another site, it’s still available in the browser cache.

But what if the CDN you’re using goes down? To fix this you can use a CDN fallback. For more details I recommend reading Scott Hanselmans post on the subject.

The ASP.NET team added a CDN fallback feature to the latest (prerelease) version of the ASP.NET Web Optimizations library. To use it, specify a CdnFallBackExpression.  This expression will be checked and if the expression fails, the fallback URL will be used(a local reference to jQuery in this sample):

Thursday, May 16, 2013

Team Foundation Server 2012: create a direct link to a work item

Team Foundation Server always allowed you to directly browse to a specific work item by calling a very specific URL. In Team Foundation Server 2012, this URL has changed to

http://tfsservername:8080/tfs/web/wi.aspx?pcguid={collectionguid}&id={workitemid}

Replace the {workitemid} part by the id of the work item and the {collectionguid} part by the GUID of your TFS collection.

How to get this collection GUID?

The easiest way to know the collection GUID(without querying the TFS configuration database directly) is to follow the steps below:

  • Open Team Explorer
  • Connect to the TFS collection you want to use
  • Open a work item in this collection(doesn’t matter which one)
  • Right click on the work item and choose Copy Full Path

image 

  • Paste the path into notepad and you’ll find the correct GUID

image

Wednesday, May 15, 2013

Entity Framework: Explicit Loading

One of the features that Entity Framework offers is Explicit Loading. This allows you to lazily load related entities, even with lazy loading disabled. The only difference is that you need a explicit call to do it(by using the Load method on the related entity’s entry):

But what if you want to filter the child results you get back. For example, imagine that you only want to know the female students in your class(no idea why you would want to know this Glimlach

Let’s try to change our code to do this:

However if we look at the results we get back, it still contains all students. To enable filtering when using explicit loading, you’ll have to make sure that LazyLoading is disabled. If we change the code to incorporate this, it will work as expected:

Tuesday, May 14, 2013

SQL Server: see which users are connected to your database

There are multiple ways to see which users are connected to your SQL Server database. Probably the easiest way is to use the built in stored procedure called sp_who2.

To use it, execute the following steps:

  • Open SQL Server Management Studio
  • Connect to the database server you want to monitor
  • Click on the New Query button to open the SQL editor
  • Paste the sp_who2 command in the SQL Editor

image

  • Click Execute

image

  • In the results window you’ll find a list of logins, database names, status, command, program name, CPU time, Login time and so on.

image

Monday, May 13, 2013

Team Foundation Server 2012: Work item link type end '' does not exist

After upgrading a customers TFS environment to Team Foundation Server 2012(Update 2), some minor issues were found. One of the more interesting issues was the following one:

When opening the Team Foundation Server Web Access, a specific work item query always failed with the following JavaScript error:

Work item link type end '' does not exist.TFS.WorkItemTracking.LinkTypeEndDoesNotExistException: Work item link type end '' does not exist.
   at findLinkTypeEnd (
http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.WorkItemTracking.min.js?__loc=en-US:4:28677)
   at getColumnValue (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.WorkItemTracking.Controls.Query.min.js?__loc=en-US:4:30154)
   at getColumnText (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.UI.Controls.Grids.min.js?__loc=en-US:4:12128)
   at _drawCell (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.UI.Controls.Grids.min.js?__loc=en-US:4:10896)
   at _updateRow (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.UI.Controls.Grids.min.js?__loc=en-US:4:10331)
   at _updateRow (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.WorkItemTracking.Controls.Query.min.js?__loc=en-US:4:40857)
   at _drawRows (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.UI.Controls.Grids.min.js?__loc=en-US:4:8529)
   at _updateViewport (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.UI.Controls.Grids.min.js?__loc=en-US:4:30553)
   at _redraw (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.UI.Controls.Grids.min.js?__loc=en-US:4:32717)
   at redraw (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.UI.Controls.Grids.min.js?__loc=en-US:4:11986)

After this happens, everything else on the webpage starts to fail too and the only way to solve this is by doing a full page refresh.

The strange thing was that when opening the same work item query using Team Explorer, it just worked. This set me in the wrong direction because it made me think that the issue was related to the web access and not to the work item query itself.

But in the end I found it, the work item query was using the LinkType column which is not available in TFS 2012. To remove this column, execute the following steps:

  • Open the work item query
  • Go to Column Options
  • Select the column you want to remove from the Selected Columns list and click on the ‘<’ button to remove it.
  • Click OK to apply the changes

Friday, May 10, 2013

Useful PowerShell scripts for SharePoint

While converting and merging some SharePoint sites, I created some PowerShell scripts to speed up the process.

In case I’ll ever need them again, I post them here:

Script 1: Mount a Content database using PowerShell
Script 2: Generate a sub site using PowerShell
Script 3: Generate a Document Library using PowerShell
Script 4: Remove a site collection(without asking for confirmation) using PowerShell