Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Triggers
Message
 
 
To
24/06/2008 14:32:47
General information
Forum:
Microsoft SQL Server
Category:
Other
Title:
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01326457
Message ID:
01326462
Views:
13
>Hi All,
>
>Is there a way in Triggers to do like we do in vfp - Try catch. So that when a process fails, like a call to a vfp dll, the trigger will stop and not be a continues process until you kill it?

Yes. Check TRY/CATCH in SQL Server 2005.

There is a sample from my SP based on Kevin Goff article:
BEGIN TRY
    --code
        END TRY
BEGIN CATCH
		DECLARE @ErrorSeverity int, @ErrorNumber int, 
            @ErrorMessage nvarchar(4000), @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 = 'Can not register a new person' + 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

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

        -- If the error renders the transaction as uncommittable, we must rollback
        IF XACT_STATE() < 0
            ROLLBACK TRANSACTION
       
    END CATCH  
	RETURN @@Error
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform