I am using sql server 2008 which is communicating to java web service which is communicationg to asp.net application.
I have written stored procedure as follows:
create procedure abc(@intA int,@intB int,@intOutputParameter int output)
as
begin
insert into tbluser(A,B) values (@intA,@intB)
/*where B is foregin key */
set @intOutputParameter = IDENT_CURRENT ('tbluser')
end
/*where B is foregin key */
–now when i am passing B as which is not present in master table it is throwing me error (In sql server 2008 )which is obsullatly fine and accepted
But In java web method s My sp is geeting executed and my insert statement is not getting executed and directly the statement after insert is getting executed (identity_current(“Tbluser”)) …why is it so
If u need more explanition please ask for it…
a) Your
@intOutputParameterparameter is not declared as output; use:b) Are you positive that table
tbluserhas something likeid int IDENTITY(1,1)?c) What’s with the
begin end?UPDATE:
You could solve this by using try-catch inside the procedure, like:
This will return -1 in case of an error, so if your table IDs are >1, then the Java application can differentiate between successful insert and an error.