Ms Sql Stored Procedure Return Error
Contents |
360 games PC games sql server stored procedure raiserror Windows games Windows phone games Entertainment All Entertainment return error message from stored procedure to c# Movies & TV Music Business & Education Business Students & educators stored procedure error codes Developers Sale Sale Find a store Gift cards Products Software & services Windows Office Free downloads & security Internet
Sql Server Stored Procedure Error Handling
Explorer Microsoft Edge Skype OneNote OneDrive Microsoft Health MSN Bing Microsoft Groove Microsoft Movies & TV Devices & Xbox All Microsoft devices Microsoft Surface All Windows PCs & tablets PC accessories Xbox & games Microsoft Lumia All incorrect syntax near raiseerror Windows phones Microsoft HoloLens For business Cloud Platform Microsoft Azure Microsoft Dynamics Windows for business Office for business Skype for business Surface for business Enterprise solutions Small business solutions Find a solutions provider Volume Licensing For developers & IT pros Develop Windows apps Microsoft Azure MSDN TechNet Visual Studio For students & educators Office for students OneNote in classroom Shop PCs & tablets perfect for students Microsoft in Education Support Sign in Cart Cart Javascript is disabled Please enable javascript and refresh the page Cookies are disabled Please enable cookies and refresh the page CV: {{ getCv() }} English (United States) Terms of use Privacy & cookies Trademarks © 2016 Microsoft
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack how to display message in sql stored procedure Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow
How To Find Error In Stored Procedure In Oracle
is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Return value from a
Return Error Message From Stored Procedure Oracle
stored proc on error up vote 14 down vote favorite 3 I have an sp in SQL Server that when errors returns -4 What does -4 mean? Is there a table somewhere explaining what the possible return values are? There must be some https://support.microsoft.com/en-us/kb/321903 standard For example declare @RetVal int EXEC @RetVal = stpTest select @RetVal where stpTest is "SELECT 1/0" returns -6. -6 must mean something! The sp that returned -4 only has UPDATE and SELECT INTO statements in it. At no point does it do 'SELECT -4' so how can I "find out what -4 means in that particular stored procedure"? Also, if there is no standard then why does a divide by zero error always return -6? If you have an sp that does not return anything http://stackoverflow.com/questions/1035789/return-value-from-a-stored-proc-on-error i.e. it doesn't have any select statements in it and you do: declare @RetVal int EXEC @RetVal = yourSPName Then @RetVal will have a value of 0. If there is an error then @RetVal will be a value other then zero, for example if the only thing your sp does is "SELECT 1/0" then @RetVal will be -6. Try it and see My question is what do these return values mean? They must have some logical meaning! sql sql-server stored-procedures return-value share|improve this question edited Nov 5 '11 at 14:27 marc_s 454k938701033 asked Jun 23 '09 at 23:30 Steve As is stated repeatedly below, there are no standards. If you have the source of the sproc, try your standard debugging procedures. –Adrien Jun 23 '09 at 23:49 Which version of SQL Server are you using? Please edit your question with a complete example, showing the stored procedure, the execution, and the result. –John Saunders Jun 24 '09 at 0:19 add a comment| 5 Answers 5 active oldest votes up vote 19 down vote If you have a RETURN statement with an explicit return value, that is of course the return value. But if there is no RETURN statement, but an error occurs during execution, the return value is 10 minus the severity level of the error. Division by zero is level 16, thus the return value is -6. Permissions errors are typical level 14, thus the return value is -4. As you may guess this is not terribly useful, but this: 0 is
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow http://stackoverflow.com/questions/33277548/return-error-message-from-stored-procedure the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Return error message from stored procedure up vote 0 down vote favorite The question should be quit simple, stored procedure but I can't figure out the answer nor why my sp is not working. CREATE PROCEDURE spTest_Delete @ID int AS begin tran declare @err int declare @errMesage nvarchar(max) set @errMesage = '' set @err = 0 delete from Test where ID = @ID set @err = @@ERROR set @errMesage = ERROR_MESSAGE() if @err = 0 commit tran else begin RAISERROR(N'Could not delete !Error nr: %d. Message: %s', 1, 16, @err, @errMesage) rollback tran sql stored procedure end This procedure runs ok, but in case of FK constraint on the delete statement it runs into an error (which is good) and I would like to catch the error. Msg 547, Level 16, State 0, Procedure spTest_Delete, Line 12 The DELETE statement conflicted with the REFERENCE constraint "FK_TEstFK_Test". The conflict occurred in database "Test", table "dbo.Test", column 'ID'. The statement has been terminated. Could not delete! Error nr: 547. Message: (null) Msg 50000, Level 1, State 16 I always get null for my message variable, even though the delete statement throws an error. sql-server stored-procedures sql-server-2012 share|improve this question edited Oct 22 '15 at 10:22 marc_s 454k938701033 asked Oct 22 '15 at 9:22 CiucaS 1,185724 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote accepted Try to use TRY CATCH and catch your error like this: BEGIN TRY delete from Test where ID = @ID END TRY BEGIN CATCH SET @ErrorMessage = ERROR_MESSAGE() SET @ErrorSeverity = ERROR_SEVERITY() SET @ErrorState = ERROR_STATE() RAISERROR(@ErrorMessage, @ErrorSeverity, @ErrorState) BREAK END CATCH share|improve this answer answered Oct 22 '15 at 9:26 Rahul Tripathi 101k1595173 Try catch did the trick, but I'm still a little confused, why it doesn't work without try catch. –CiucaS Oct 22 '15 at 9:28 @Ciuc