Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 0, current count = 1

Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 0, current count = 1


Hatalı:
BEGIN
SET NOCOUNT ON;
BEGIN TRAN
BEGIN TRY
IF(...)
BEGIN
...
COMMIT TRAN
SELECT 1
END
END TRY
BEGIN CATCH
ROLLBACK TRAN
SELECT ERROR_MESSAGE() -- işlem başarısız
END CATCH
END

Doğru:
BEGIN
SET NOCOUNT ON;
IF(...)
BEGIN TRY
BEGIN TRAN
...
COMMIT TRAN
SELECT 1
END TRY
BEGIN CATCH
ROLLBACK TRAN
SELECT ERROR_MESSAGE() -- işlem başarısız
END CATCH
END

search this blog (most likely not here)