Advertisement
Guest User

StoredProcedureWithError-no-transactions

a guest
Feb 6th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.54 KB | None | 0 0
  1. USE [example_database]
  2. GO
  3. /****** Object:  StoredProcedure [dbo].[test_error_cannot_insert_null]    Script Date: 2/6/2019 1:59:21 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. -- =============================================
  9. -- Author:      Gary Reckard
  10. -- Create date: 2019-06-19
  11. -- Description: testing error reporting from calling procedures
  12. -- =============================================
  13. ALTER PROCEDURE [dbo].[test_error_cannot_insert_null]
  14. AS
  15. BEGIN
  16.  
  17.  
  18.  
  19.     BEGIN TRY
  20.    
  21.         --------------------------------------------------
  22.         -------------///// BEGIN SQL \\\\\----------------
  23.         --------------------------------------------------
  24.  
  25.             --this should fail!
  26.             INSERT INTO [roles]
  27.                 (
  28.                     name,
  29.                     description
  30.                 )
  31.             VALUES
  32.                 (
  33.                     null,
  34.                     null
  35.                 );
  36.  
  37.         --------------------------------------------------
  38.         --------------\\\\\ END SQL /////-----------------
  39.         --------------------------------------------------
  40.  
  41.  
  42.  
  43.     END TRY
  44.     BEGIN CATCH        
  45.         DECLARE @errorProcedure varchar(100) = ERROR_PROCEDURE(),
  46.                 @errorShort varchar(255)     = ERROR_MESSAGE(),
  47.                 @errorCode varchar(50)       = ERROR_NUMBER(),
  48.                 @errorLine int               = ERROR_LINE(),  
  49.                 @errorSeverity int           = ERROR_SEVERITY(),
  50.                 @errorState int              = ERROR_STATE(),  
  51.                 @xstate int                  = XACT_STATE();
  52.  
  53.        
  54.         -- Log errors
  55.         EXEC errors_add @errorCode, @errorProcedure,  @errorShort, NULL, @errorLine, @errorSeverity, @errorState, @xstate;
  56.  
  57.         THROW;
  58.         RETURN;
  59.     END CATCH          
  60.  
  61. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement