Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Confusing error message

$
0
0

Hi everybody,

I am getting this error message when I try to run the same SQL Server stored procedure using different parameters:

---------------------------
Error accessing server data
---------------------------
A SQL Server ODBC connection error occurred...



Program:  VENUECONFIGURATION.DELETERECORD

ODBC Error Message:  Problem deleting Level 116
SQL Server Error Message is: 102 in procedure: siriussp_rsDeleteSection Line: 79 Error text: Incorrect syntax near 'BEGI'.

ODBC SQL State:                37000
ODBC Data Source Error:   50000
ODBC Connection Handle:  2
------------------------------------

SQL Statement:

execute dbo.siriussp_rsDeleteLevel 116
---------------------------
OK   
---------------------------

I've been able to duplicate this problem in SSMS as well then I tried to run two statements:

execute dbo.siriussp_rsDeleteLevel 116

go

execute dbo.siriussp_rsDeleteLevel 117

---------------------------------------------------------

Apparently the problem is in the temp table I am using in these procedures. 

Can someone please help me out to figure out what the problem may be? This is the code for the delete_section procedure as the error indicates a problem in that procedure:

ALTER PROCEDURE [dbo].[siriussp_rsDeleteSection] (@SectionID INT = NULL)
AS
BEGIN
	SET NOCOUNT ON;

	IF @SectionID IS NULL
		AND OBJECT_ID(N'tempdb..#DelSections', N'U') IS NULL
		BEGIN
			RAISERROR('Invalid siriussp_rsDeleteSection procedure call!', 16, 1);
			RETURN - 2;-- bad call
		END

	DECLARE @ErrorMessage NVARCHAR(4000)
		,@Descrip VARCHAR(100);

	IF @SectionID IS NOT NULL
		AND EXISTS (
			SELECT 1
			FROM dbo.rsHolds H
			WHERE SectionId = @SectionID
				AND HoldExpire > CURRENT_TIMESTAMP
				AND IsEnabled = 1
			)
	BEGIN
		SELECT @Descrip = descrip
		FROM dbo.rsSections
		WHERE SectionID = @SectionID;

		SET @ErrorMessage = 'Section ' + CAST(@SectionID AS VARCHAR(20)) + '(' + @Descrip + ') can not be deleted since there are existing holds referencing that section';

		RAISERROR (
				@ErrorMessage
				,16
				,1
				);

		RETURN - 1;
	END

	IF @SectionID IS NOT NULL
		AND EXISTS (
			SELECT 1
			FROM dbo.rsSeats S
			WHERE SectionId = @SectionID
				AND trans_no <> 0
			)
	BEGIN
		SELECT @Descrip = descrip
		FROM dbo.rsSections
		WHERE SectionID = @SectionID;

		SET @ErrorMessage = 'Section ' + CAST(@SectionID AS VARCHAR(20)) + '(' + @Descrip + ') can not be deleted since there are sold Seats referencing that section';

		RAISERROR (
				@ErrorMessage
				,16
				,1
				);

		RETURN - 1;
	END
	DECLARE @DelSections TABLE (SectionID INT PRIMARY KEY);
	
	IF @SectionID IS NOT NULL
	
		INSERT INTO @DelSections (SectionID)
		SELECT SectionID
		FROM dbo.rsSections
		WHERE SectionID = @SectionID;
	
	ELSE
		INSERT INTO @DelSections (SectionID)
		SELECT SectionID FROM #DelSections;
	
	BEGIN TRY
		IF OBJECT_ID('TempDB..#DelBlocks', 'U') IS NOT NULL
			DROP TABLE #DelBlocks;

		SELECT BlockId
		INTO #DelBlocks
		FROM dbo.rsTSBlocks B
		WHERE B.SectionID IN (
				SELECT SectionID
				FROM @DelSections
				);

		BEGIN TRANSACTION

		DELETE
		FROM dbo.rsSeats
		WHERE SectionID IN (
				SELECT SectionID
				FROM @DelSections
				);

		DELETE
		FROM dbo.rsHolds
		WHERE SectionID IN (
				SELECT SectionID
				FROM @DelSections
				);

		DELETE
		FROM dbo.rsSectLink
		WHERE SectionID IN (
				SELECT SectionID
				FROM @DelSections
				);

		DELETE
		FROM dbo.rsSectionAvailabilityRules
		WHERE SectionID IN (
				SELECT SectionID
				FROM @DelSections
				);

		execute dbo.siriussp_rsDeleteBlock ;

		-- Sections
		DELETE S
		FROM dbo.rsSections S
		WHERE S.SectionID IN (
				SELECT SectionID
				FROM @DelSections
				);

		COMMIT TRANSACTION
	END TRY

	BEGIN CATCH
		DECLARE @ErrorSeverity INT
			,@ErrorNumber INT
			,@ErrorState INT
			,@ErrorLine INT
			,@ErrorProc NVARCHAR(200)

		-- Grab error information from SQL functions
		SET @ErrorSeverity = ERROR_SEVERITY()
		SET @ErrorNumber = ERROR_NUMBER()
		SET @ErrorMessage = ERROR_MESSAGE()
		SET @ErrorState = ERROR_STATE()
		SET @ErrorLine = ERROR_LINE()
		SET @ErrorProc = ERROR_PROCEDURE()
		SET @ErrorMessage = 'Problem deleting Section ' + CAST(@SectionID AS VARCHAR(10)) + CHAR(13) + 'SQL Server Error Message is: ' + CAST(@ErrorNumber AS VARCHAR(10)) + ' in procedure: ' + @ErrorProc + ' Line: ' + CAST(@ErrorLine AS VARCHAR(10)) + ' Error text: ' + @ErrorMessage

		-- Not all errors generate an error state, to set to 1 if it's zero
		IF @ErrorState = 0
			SET @ErrorState = 1

		-- If the error renders the transaction as uncommittable or we have open transactions, we may want to rollback
		IF @@TRANCOUNT > 0
		BEGIN
			ROLLBACK TRANSACTION
		END

		RAISERROR (
				@ErrorMessage
				,@ErrorSeverity
				,@ErrorState
				,@ErrorNumber
				)
	END CATCH

	RETURN @@ERROR;
END


For every expert, there is an equal and opposite expert. - Becker's Law


My blog


My TechNet articles


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>