@@ -1057,7 +1057,9 @@ BEGIN TRY
10571057
10581058 -- insert columns for clustered indexes and heaps
10591059 -- collect info on identity columns for this one
1060- SET @dsql = N' SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
1060+ SET @dsql = N' /* sp_BlitzIndex */
1061+ SET LOCK_TIMEOUT 1000; /* To fix locking bug in sys.identity_columns. See Github issue #2176. */
1062+ SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
10611063 SELECT ' + CAST (@DatabaseID AS NVARCHAR (16 )) + ' ,
10621064 s.name,
10631065 si.object_id,
@@ -1121,10 +1123,30 @@ BEGIN TRY
11211123 PRINT SUBSTRING (@dsql, 32000 , 36000 );
11221124 PRINT SUBSTRING (@dsql, 36000 , 40000 );
11231125 END ;
1124- INSERT #IndexColumns ( database_id, [schema_name], [object_id], index_id, key_ordinal, is_included_column, is_descending_key, partition_ordinal,
1125- column_name, system_type_name, max_length, precision , scale, collation_name, is_nullable, is_identity, is_computed,
1126- is_replicated, is_sparse, is_filestream, seed_value, increment_value, last_value, is_not_for_replication )
1127- EXEC sp_executesql @dsql;
1126+ BEGIN TRY
1127+ INSERT #IndexColumns ( database_id, [schema_name], [object_id], index_id, key_ordinal, is_included_column, is_descending_key, partition_ordinal,
1128+ column_name, system_type_name, max_length, precision , scale, collation_name, is_nullable, is_identity, is_computed,
1129+ is_replicated, is_sparse, is_filestream, seed_value, increment_value, last_value, is_not_for_replication )
1130+ EXEC sp_executesql @dsql;
1131+ END TRY
1132+ BEGIN CATCH
1133+ RAISERROR (N ' Failure inserting data into #IndexColumns for clustered indexes and heaps.' , 0 ,1 ) WITH NOWAIT ;
1134+
1135+ IF @dsql IS NOT NULL
1136+ BEGIN
1137+ SET @msg= ' Last @dsql: ' + @dsql;
1138+ RAISERROR (@msg, 0 , 1 ) WITH NOWAIT ;
1139+ END ;
1140+
1141+ SELECT @msg = @DatabaseName + N ' database failed to process. ' + ERROR_MESSAGE (),
1142+ @ErrorSeverity = 0 , @ErrorState = ERROR_STATE ();
1143+ RAISERROR (@msg,@ErrorSeverity, @ErrorState )WITH NOWAIT ;
1144+
1145+ WHILE @@trancount > 0
1146+ ROLLBACK ;
1147+
1148+ RETURN ;
1149+ END CATCH ;
11281150
11291151
11301152 -- insert columns for nonclustered indexes
0 commit comments