The following code returns this message in case something goes wrong:
Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 0, current count = 1.
OPEN extensionViews FETCH NEXT FROM extensionViews INTO @Viewname WHILE @@FETCH_STATUS = 0 BEGIN BEGIN TRY exec sp_refreshview @Viewname END TRY BEGIN CATCH print 'ERROR sp_refreshview' END CATCH FETCH NEXT FROM extensionViews INTO @Viewname END CLOSE extensionViews DEALLOCATE extensionViews
I already found out that there is something going wrong with the implicit transactions, but I do not really understand it entirely.
In case of a CATCH, do I have to explicitly ROLLBACK the transaction? Does this mean that I have to start the transaction explicitly as well insode of the Cursor to rollback THIS one command instead of all?