none
Throw an exception from sp RRS feed

  • Question

  •  

    Hi Guys,,,,

    i have a problem that if any error exist in the insert command in the stored procedure, there is no throw for an exception on my code. only return -1,

     

    my question is???? is that a normal case!!!!

    if its how i can throw an exception from the stored procedure !!!!

    and am sorry sorry for my bad english!!!

    Sunday, June 15, 2008 2:20 PM

All replies

  • here's how e handle error  in sql server:

     

    In the olden days we use the @@error

     

    Now in the Yukon times we have

    the Try... Catch block

     

    you may also use the SP's return value

     

    http://www.sql-server-performance.com/articles/dev/stored_procedure_returns_p1.aspx

     

     

    the -1 might be a return value

    Monday, June 16, 2008 9:28 AM
  • Thanx joeydj for your reply....

    but @@error and try...catch block don't throw an exception on my c# code

    you will say that i can handle the return value and throw an exception from my code depend on the value

    of the return value.. but this will cause some complication on my application for some reasons.

    if you have any idea to cause an exception on my code from the stored procedure pls. tell me

    and thank you again

    Monday, June 16, 2008 9:42 AM
  • By default - assuming there are no triggers or instead of insert triggers

     

    If the insert fails its gonna throw an exemption....

    please post the Sp's DDL if its okay.

    Monday, June 16, 2008 10:02 AM
  • ELSE IF NOT EXISTS(SELECT *

    FROM hr_EmployeePosition WHERE intEmployeeID=@intEmployeeID)

    BEGIN

    INSERT INTO hr_EmployeePosition(intPositionID,intEmployeeID,

    curSalary,intExperienceYears,dtEmployedDate,

    dtContractEndDate,strContractDuration,

    intContractTypeID,intNumberOfDays,

    curDailyPayment,bTax,bOverTime,bSocialSecurity,

    bMedicalInsurance,bYearlyGrowth)

    VALUES(@intPositionID,@intEmployeeID,

    @curSalary,@intExperienceYears,@dtEmployedDate,

    @dtContractEndDate,@strContractDuration,

    @intContractTypeID,@intNumberOfDays,

    @curDailyPayment,@bTax,@bOverTime,@bSocialInsurance,

    @bMedicalInsurance,@bYearlyGrowth)

    SET @RESULT='SUCCESSFUL OPERATION'

    END

     ------------------------------------------------------------------------------

     

    curSalary not allow null, if i pass null value to @curSalary parameter there is no throw to any exception on my Code

    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    this is very weird!!!!!!!!

    Monday, June 16, 2008 3:25 PM
  • Hi noor,

     

    Is this the ddl for the entire Sp?

    It seems incomplete.

     

     

    thanks,

    joey

    Thursday, June 19, 2008 6:31 AM