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
[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
I think either you commited or possibly rolled back ur transaction before this line, posssiblly u missed a return statement there
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
if @@TRANCOUNT > 0
ROLLBACK TRAN
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(fa cilityname ))) 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
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(fa
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thx Guys