{"id":118,"date":"2012-01-12T10:24:41","date_gmt":"2012-01-12T10:24:41","guid":{"rendered":"https:\/\/sqlserverlearner.azurewebsites.net\/2012\/01\/12\/the-rollback-transaction-request-has-no-corresponding-begin-transaction\/"},"modified":"2012-01-12T10:24:41","modified_gmt":"2012-01-12T10:24:41","slug":"the-rollback-transaction-request-has-no-corresponding-begin-transaction","status":"publish","type":"post","link":"https:\/\/sqlserverlearner.com\/2012\/01\/12\/the-rollback-transaction-request-has-no-corresponding-begin-transaction\/","title":{"rendered":"The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION."},"content":{"rendered":"
While using transactions in SQL Server sometimes you get the following errors:<\/p>\n
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION. Cause For this error:<\/strong> Replication of the scenario:<\/strong><\/em> In the above query the first COMMIT TRAN statement has commited the transaction started by BEGIN TRAN, When the second COMMIT TRAN statement is executed the error The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION<\/strong> occurs.<\/p>\n Same is the case for ROLLBACK TRAN in the below query. Fix For this error:<\/strong><\/em><\/p>\n As a best practice always check for open transactions before issuing COMMIT TRAN or ROLLBACK TRAN statement. [sql] [sql] This way the commit\/rollback tansaction error can be avoided.<\/strong><\/em><\/p>\n Other Such Scenarios:<\/strong><\/p>\n [sql] [sql] [sql] While using transactions in SQL Server sometimes you get the following errors: The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION. The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION. Cause For this error: There is no transaction in progress but the COMMIT\/ROLLBACK TRANSACTION request is issued. Replication of the scenario: [sql] BEGIN TRAN COMMIT…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[128,3],"tags":[744,745,746,747,748,749,750,751,752,753,754,755,756,757],"class_list":["post-118","post","type-post","status-publish","format-standard","hentry","category-sql-errors","category-sqlserverpedia-syndication","tag-avoid-rollback-tansaction-error","tag-error-the-commit-transaction-request","tag-error-the-rollback-transaction-request","tag-fix-the-rollback-transaction-request-has-no-corresponding-begin-transaction","tag-how-to-fix-error-the-rollback-transaction-request-has-no-corresponding-begin-transaction","tag-how-to-use-trancount","tag-resolve-the-rollback-transaction-request-has-no-corresponding-begin-transaction","tag-rollback-commit-error","tag-the-commit-transaction-request-has-no-corresponding","tag-the-commit-transaction-request-has-no-corresponding-begin-transaction","tag-the-rollback-transaction-request-has-no-corresponding","tag-trancount","tag-using-trancount","tag-why-do-i-get-the-rollback-transaction-request-has-no-corresponding-begin-transaction-error"],"_links":{"self":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/comments?post=118"}],"version-history":[{"count":0,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/118\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/media?parent=118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/categories?post=118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/tags?post=118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\nThe COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.<\/strong><\/p>\n
\nThere is no transaction in progress but the COMMIT\/ROLLBACK TRANSACTION request is issued.<\/p>\n
\n[sql]
\nBEGIN TRAN
\nCOMMIT TRAN
\nCOMMIT TRAN
\n[\/sql]<\/p>\n
\n[sql]
\nBEGIN TRAN
\nROLLBACK TRAN
\nROLLBACK TRAN
\n[\/sql]<\/p>\n
\n@@TRANCOUNT can be used to find the number of open transactions.<\/p>\n
\nIF(@@TRANCOUNT>0)
\nCOMMIT TRAN
\n[\/sql]<\/p>\n
\nIF(@@TRANCOUNT>0)
\nROLLBACK TRAN
\n[\/sql]<\/p>\n
\nBEGIN TRAN
\nCOMMIT
\nCOMMIT
\n[\/sql]<\/p>\n
\nBEGIN TRAN
\nCOMMIT WORK
\nCOMMIT WORK
\n[\/sql]<\/p>\n
\nBEGIN TRAN
\nROLLBACK WORK
\nROLLBACK WORK
\n[\/sql]<\/p>\n","protected":false},"excerpt":{"rendered":"