Sample Header Ad - 728x90

Transaction Error in TRY CATCH block

1 vote
3 answers
1906 views
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?
Asked by Magier (4827 rep)
Sep 22, 2016, 08:10 AM
Last activity: Jan 11, 2025, 01:34 PM