I found a good solution to use that might help others. I start by getting the list of transactions with locks on the current table using :
USE [Your DB Name]
SELECT REQUEST_MODE, REQUEST_TYPE, REQUEST_SESSION_ID
FROM sys.dm_tran_locks
WHERE RESOURCE_TYPE = 'OBJECT'
AND RESOURCE_ASSOCIATED_ENTITY_ID =(SELECT OBJECT_ID('YourTableName'))
The REQUEST_SESSION_ID
is the ID of the session which has the lock set on the table. Then I run EXEC sp_who2
to make sure that the SPID is the one for the expected service. All I needed to do at the end was KILL <SPID>
and rebuild the index. You might need to do it multiple time if you are building more than one index as the lock could be set again.