I want to recover the same exception in sql server that occurred in my try block. I can throw the same message, but I want to throw the same error.
BEGIN TRANSACTION BEGIN TRY INSERT INTO Tags.tblDomain (DomainName, SubDomainId, DomainCode, Description) VALUES(@DomainName, @SubDomainId, @DomainCode, @Description) COMMIT TRANSACTION END TRY BEGIN CATCH declare @severity int; declare @state int; select @severity=error_severity(), @state=error_state(); RAISERROR(@@Error,@ErrorSeverity,@state); ROLLBACK TRANSACTION END CATCH
RAISERROR(@@Error, @ErrorSeverity, @state);
This line will show an error, but I want something like this. This causes an error with error number 50000, but I want the erron number to be selected, that I pass @@error ,
I want to fix this error no at frontend
i.e.
catch (SqlException ex) { if ex.number==2627 MessageBox.show("Duplicate value cannot be inserted"); }
I want this functionality. which cannot be achieved by leveling up. I do not want to give a custom error message on the back panel.
RAISEERROR should return below the specified error when I pass ErrorNo to throw in catch
Msg 2627, Level 14, State 1, Procedure spOTest_DomainInsert,
Line 14 Violation of UNIQUE KEY 'UK_DomainCode' constraint. Cannot insert duplicate key in object 'Tags.tblDomain. Application completed.
EDIT:
What could be the drawback of using the catch try block if I want the exception to be handled in the front, given the stored procedure, it contains several queries that need to be executed
sql database sql-server tsql exception-handling
Shantanu Gupta Mar 20 2018-10-10T00: 00Z
source share