Posted this earlier under SQL 7, 2000 T-SQL Section. Have deleted that one and reposting under SQL 2005.
I am trying to Raise an error using RAISERROR function in sql when the XML schema validation fails.
I am doing this inside a store proc. I am declaring the XML doc binding it to it's XSD schema in the TRY block and if validation fails, raise a user define error number by using RAISERROR function in the catch block. However, somehow i am not able to do this and sql return it's own error the moment it executes that line of code. So using Employee example here, I am doing something like this.
CREATE PROC ImportEmployeeInfo
@EmployeeXML as XML
DECLARE @EmpXML AS XML(EmployeeSchema) --declaring a local XML variable and binding it to its XSD Schema Collection
SET @EmpXML = @EmployeeXML -- here I am setting the @EmpXML to @EmployeeXML variable passed in
IF @@error<>0 --if the @EmployeeXML failed the XSD validation, i beileve there would be an error right however this line never gets executed
SET @LocalError = 50001 --user defined error
RAISERROR(' The input parameter @EmployeeXML is not valid', 16, 1)
--The XML shredding and import into table goes here
--I have another another user defined errorhandler proc here which will take the above @LocalError
--as input parameter and raise a detailed error
END --End of Proc