I am new to running transactions and I am getting the error "Transaction count after execute indeicates a mismatching number of begin and commit statements. Previous count = 1, current count = 0". Can anyone look at the below code and tell me what might be wrong? I am calling Proc 1 which calls Proc 2Proc 1*ALTER proc [dbo].[spRaces] @UpdateType as char(6), @RaceID as int = null, @SectionID as smallint = null, @Race as varchar(50) = null, @RaceDescription as varchar(MAX) = nullasset nocount onset xact_abort onset arithabort ondeclare @ErrorNum intbegin transaction--Process a new raceif (@UpdateType = 'Insert')begin insert into dbo.Races (SectionID, Race, RaceDescription) values (@SectionID, @Race, @RaceDescription); select @ErrorNum = @@ERROR; if (@ErrorNum = 0) begin exec @ErrorNum = dbo.spSubMenuItems @SectionID, 'Information', 'Races', 'Races', 'Races'; end endelse--Process an updated raceif (@UpdateType = 'Update')begin update dbo.Races set SectionID = coalesce(@SectionID, SectionID), Race = coalesce(@Race, Race), RaceDescription = coalesce(@RaceDescription, RaceDescription) where ID = @RaceID; select @ErrorNum = @@ERROR;endelse--Process a race removalif (@UpdateType = 'Delete')begin delete dbo.Races where ID = @RaceID; select @ErrorNum = @@ERROR;endif (@ErrorNum = 0)begin insert into dbo.SiteUpdates (SectionIDUpdated, SubSectionName, UpdatedItemName, UpdateType) values (@SectionID, 'Races', @Race, @UpdateType); select @ErrorNum = @@ERROR;endif (@ErrorNum = 0)begin commitendelsebegin rollbackendreturn @ErrorNum;
proc 2:ALTER proc [dbo].[spSubMenuItems]@SectionID as smallint,@MenuTitle as char(11),@FileName as varchar(50),@LinkTitle as varchar(50),@LinkName as varchar(50)asset nocount onset xact_abort onset arithabort ondeclare @ErrorNum intbegin transactionif not exists (select 1 from dbo.SectionMenu where SectionID = @SectionID and MenuTitle = @MenuTitle)begin insert into dbo.SectionMenu (SectionID, MenuTitle, FileName, LinkTitle, LinkName) values (@SectionID, @MenuTitle, @FileName, @LinkTitle, @LinkName); set @ErrorNum = @@Error;endif (@ErrorNum = 0)begin commitendelsebegin rollbackendreturn @ErrorNum
-- If I get used to envying others...Those things about my self I pride will slowly fade away.-Stellvia