ERROR
Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 0, current count = 1.
I get this error in my Stored Procedure that I cannot see where.
ALTER PROCEDURE [dbo].[UpsertServiceTicket]
@TransactionType INT,
@Id INT = NULL,
@CreationDateTime DATETIME = GETDATE,
@Issue VARCHAR(MAX),
@ReportedDateTime DATETIME = NULL,
@ResolutinoDateTime DATETIME = NULL,
@CreatedBy INT = NULL,
@ServiceRequestNumber NVARCHAR(MAX),
@Status VARCHAR(MAX) = NULL,
@IsDeleted BIT = 0,
@LocationId INT,
@SubLocationId INT,
@RequestorId INT,
@ConfirmedBy INT = NULL,
@DepartmentId INT,
@ErrorMessage NVARCHAR(1000) OUTPUT,
@ErrorCode SMALLINT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRY
BEGIN TRANSACTION
IF (@TransactionType = 0)
INSERT INTO ServiceTickets (
CreationDateTime
, Issue
, ReportedDateTime
, ResolutionDateTime
, CreatedBy
, ServiceRequestNumber
, [Status]
, IsDeleted
, LocationId
, SubLocationId
, RequestorId
, ConfirmerId
, DepartmentId
)
VALUES (
@CreationDateTime
, @Issue
, @ReportedDateTime
, @ResolutinoDateTime
, @CreatedBy
, @ServiceRequestNumber
, @Status
, @IsDeleted
, @LocationId
, @SubLocationId
, @RequestorId
, @ConfirmedBy
, @DepartmentId
)
-- updating the service ticket table
ELSE
UPDATE ServiceTickets
SET CreationDateTime = @CreationDateTime
, Issue = @Issue
, ReportedDateTime = @ReportedDateTime
, ResolutionDateTime = @ResolutinoDateTime
, CreatedBy = @CreatedBy
, ServiceRequestNumber = @ServiceRequestNumber
, [Status] = @Status
, IsDeleted = @IsDeleted
, LocationId = @LocationId
, SubLocationId = @SubLocationId
, RequestorId = @RequestorId
, ConfirmerId = ConfirmerId
, DepartmentId = DepartmentId
WHERE Id = @Id
SET @ErrorMessage = ERROR_MESSAGE()
SET @ErrorCode = @@ERROR
IF (@ErrorCode = 0)
COMMIT TRANSACTION
END TRY
BEGIN CATCH
SET @ErrorMessage = ERROR_MESSAGE()
SET @ErrorCode = @@ERROR;
IF @ErrorCode > 0
ROLLBACK TRANSACTION
END CATCH
END