Link to home
Start Free TrialLog in
Avatar of Glen_D
Glen_D

asked on

Rollback transaction error

I am getting this error on a sp with roleback..I believe I did start with a begin as seen below. Thx

[SQLServer]The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.

Code...

if @err = 0
begin
  commit
end
else
begin
  rollback
  raiserror('insert failed', 16,1)
end


END
Avatar of Aneesh
Aneesh
Flag of Canada image

I think either you commited or possibly rolled back ur transaction before this line, posssiblly u missed a return statement there
SOLUTION
Avatar of chapmandew
chapmandew
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
u can check the @@TRANCOUNT value which shows the no of open transaction, but i prefer you check the entire code

if @@TRANCOUNT > 0
   ROLLBACK TRAN
Avatar of Glen_D
Glen_D

ASKER

here's all my code below the variables...thx

BEGIN

      SET NOCOUNT ON;

INSERT INTO tbl_Facility (Facility_Name, Facility_Description, Building_Nos, Rooms, Shuttle_Legacy)
VALUES(@Facility_Name, @FacilityDescription, @BuildNos, @Rooms, @Shuttle_Legacy)

set @err = @@ERROR
set @MainID = SCOPE_IDENTITY()

if @err = 0
begin
insert into dbo.LU_Facility (Facility_Name)
(select distinct dbo.InitCap(ltrim(rtrim(facilityname))) as Facility from temp where facilityname not in (select facility_name from dbo.LU_Facility))
set @err = 0
end

if @err = 0
begin
  insert into tbl_Program (MainId, programID, projectID, centerID, elementID)
  values (@MainID, @Program, @Project, @Center, @Element)
  set @err = 0
end


if @err = 0
begin
  insert into tbl_Project_Req (MainId, project_req)
  values (@MainID, @Requirement)
  set @err = 0
end


if @err = 0
begin
  insert into tbl_Utilization (MainId, Need_Duration_Start, Need_Duration_End, UsageID, ReadinessID)
  values (@MainID, @StartDate, @EndDate, @UsageLvl, @Readiness_Status)
  set @err = 0
end

if @err = 0
begin
  insert into tbl_Confidence(MainId, ConfidenceID)
  values (@MainID, @ConfidenceLevel)
  set @err = 0
end

if @err = 0
begin
  insert into tbl_Operational  (MainId, LEO_TS_Development, LEO_TO, Year_TO_Begin, Lunar_TS_Development, Lunar_TO, Lunar_SD_Op)
  values (@MainID, @LEOTransSysDev, @LEOTransOps,  @YearLEOTransOpsBegan, @LunarTransSysDev, @LunarTransOps, @LunarSurfaceSysDev_Ops)
  set @err = 0
end

if @err = 0
begin
  commit
end
else
begin
  rollback
  raiserror('insert failed', 16,1)
end


END

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Glen_D

ASKER

Thx Guys