While this works great when views are valid it crashes the proc if a view won't refresh correctly.
It seems to be fine when running this with the sp_refreshsqlmodule on functions and stored procedures...if validation fails it reports it and lets you move on to the next one.
On views it always errors out...it shows the validation error and then crashes on the next view with the following error:
Validation failed for : [dbo].[vwA], Error:Invalid column name 'address'.
Validation failed for : [dbo].[vwB], Error:The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction.
Msg 3998, Level 16, State 1, Line 1
Uncommittable transaction is detected at the end of the batch. The transaction is rolled back.
Any ideas on how to trap this and move on to the next...I'm trying to generate a list of faulty views.
PS Try Catch does NOT work on views....works like a charm on Stored Procs
here is my try catch logic:
WHILE @Cnt <= @Tot BEGIN
SELECT @spname = spname
WHERE RecID = @Cnt
PRINT 'refreshing...' + @spname
EXEC sp_refreshsqlmodule @spname
PRINT 'Validation failed for : ' +
@spname + ', Error:' +
SET @Cnt = @cnt + 1