About This Blog

.net & SQL Samples, programming tips and tricks, performance tips, guidelines, and best practices

Monday 14 January 2013

TFS – Workspace Mapping issues for Different Users

I have been using TFS 2010 from quite sometime now and have found it really cool! However, the management of workspaces can be a bit tricky at times.

In real scenario, many times we come across a situation when some user has to work on someone else machine and on the same project; e.g. old team member leaves the project & a new one replaces him and is allotted the same machine, a team member might leave the company, etc. 

So, the need arises to create a new workspace & map it to the same physical folder tree to avoid replication of the files at different location. (Please note : This step can be avoided if the existing workspace was a Public Workspace). While mapping the workspace to the same folder which is already mapped to the workspace of some other user, we get a message - “The working folder {PATH} is already in use by the workspace MachineName;Username on computer MachineName.” and this is by design - that we can not map the same working folder to multiple workspaces, in order to maintain the state consistency.
Now, what is the solution to this issue. The solutions are -
  1. Remove the existing mapping.
  2. Or Delete the existing Workspace.
Workspaces can be removed using some command line TFS commands. However, there are situations when we even can not remove the workspaces; reason being, the owning domain user of the workspace to be removed - “DOES NOT EXIST” and as a workaround to this, I have written a simple SQL script, which could be executed on the TFS Database of our Project to remove the mappings.
Please note that this is not a “Supported Way”. I am sharing this just because it has worked for me and might save some of your time too. Also, please take appropriate DB backup before executing the script and if possible execute it under any DBA’s guidance. So, here is the time saver script… :)
DECLARE @WorkspaceID AS INT
DECLARE @WorkspaceName AS NVARCHAR(64)
 
--Set the Name of the Workspace whose mappings are to be removed.
SET @WorkspaceName = '{NameOfWorkspace}'
 
--Get the WorkspaceID of the Workspace to be removed.
SELECT
  @WorkspaceID = W.WorkspaceId
FROM
  dbo.tbl_Workspace W
WHERE
  W.WorkspaceName = @WorkspaceName
  
--Delete the details of working folder for this workspace.
DELETE
FROM
  dbo.tbl_WorkingFolder
WHERE
  WorkspaceID = @WorkspaceID
 
 
--Delete the mapping details for this workspace.
DELETE
FROM
  dbo.tbl_WorkspaceMapping
WHERE
  WorkspaceID = @WorkspaceID

Hope, this helps you. Also, please revert if you have some other workarounds too.