简体   繁体   中英

Receiving an error: The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION in SQL Script

Was trying to perform an update to a database for an application, and then SQL server threw me a Commit has no corresponding being transaction. It was kind enough to point me to the procedure but I cannot seem to find what the issue is.

This is my code:

ALTER PROCEDURE [dbo].[sp_tblUser_Update] @UserID             INTEGER,
                                          @UserName           NVARCHAR(20),
                                          @Password           NVARCHAR(10),
                                          @Yard               NVARCHAR(50),
                                          @NewRole            NVARCHAR(50),
                                          @FullName           NVARCHAR(50),
                                          @Email              NVARCHAR(50),
                                          @BCConEmails        BIT,
                                          @CrewStatusReadOnly BIT
AS
  BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;

      -- Insert statements for procedure here
      UPDATE tblUser
      SET    UserName = @UserName,
             UserPassword = @Password,
             Yard = @Yard,
             Fullname = @FullName,
             EmailAddress = @Email,
             NewRole = @NewRole,
             BCConEmails = @BCConEmails,
             CrewStatusReadOnly = @CrewStatusReadOnly
      WHERE  ( UserID = @UserID )
  END

GO

COMMIT 

You don't need the COMMIT line as the END in your code is what terminates the previous BEGIN . If you want to add a transaction you should put a BEGIN TRANSACTION before the update statement and move the COMMIT before the END

begin tran
delete from Customerages 
where Age=25
commit;
begin tran
delete from Customerages 
where Age=25
rollback;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM