Please help me how to solve it. why is it throwing this error as my script is inserting data into various tables extracted from an environment.
#376039 is the catch block where rollback and other raising error is happening
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.
Sign up to join this communityPlease help me how to solve it. why is it throwing this error as my script is inserting data into various tables extracted from an environment.
#376039 is the catch block where rollback and other raising error is happening
Look for a RAISERROR
statement around line #376,039 of your script.
Most likely, you are providing invalid error number 515 in a variable:
DECLARE @error integer = 515;
RAISERROR (@error, 16, 1);
Msg 2732, Level 16, State 1, Line 26
Error number 515 is invalid.
The number must be from 13000 through 2147483647 and it cannot be 50000.
You'll need to debug the script to determine how that error number is ending up in a RAISERROR
statement.
Error 515 is a system error with the following template text:
Cannot insert the value NULL into column '%.*ls', table '%.*ls';
column does not allow nulls. %ls fails.
So, the root cause will be trying to insert NULL into a column that doesn't allow NULL. You could help localise the problem by printing the ERROR_MESSAGE()
inside the CATCH
before the RAISERROR
. The ERROR_LINE()
function might also be useful.
It is generally better to use the error message rather than the error number with RAISERROR
. See Error and Transaction Handling in SQL Server by Erland Sommarskog for detailed information.
From that article:
Here is a stored procedure that showcases how you should work with errors and transactions.
CREATE PROCEDURE insert_data @a int, @b int AS SET XACT_ABORT, NOCOUNT ON BEGIN TRY BEGIN TRANSACTION INSERT sometable(a, b) VALUES (@a, @b) INSERT sometable(a, b) VALUES (@b, @a) COMMIT TRANSACTION END TRY BEGIN CATCH IF @@trancount > 0 ROLLBACK TRANSACTION DECLARE @msg nvarchar(2048) = error_message() RAISERROR (@msg, 16, 1) RETURN 55555 END CATCH