XML Validation WITH SQL

2021-05-06T22:37:49.28+00:00

Hello, I have created a stored procedure that will return the error of XML schema validation. But ERROR_MESSAGE doesn't display the full message of the error. If I replace ERROR_MESSAGE with THROW then I get the full message but I want to store the error into a string variable and I need full error.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,998 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,011 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,656 questions
{count} votes

6 answers

Sort by: Most helpful
  1. 2021-05-12T23:07:03.903+00:00

    I post my solution:

    ALTER PROCEDURE [dbo].[spValidateXMLInvDocByXML] (@XML XML, @stringXML NVARCHAR(MAX) output)
    AS BEGIN
    SET NOCOUNT ON

    DECLARE @x XML(dbo.invoicesDoc)

    BEGIN TRY     
    	SET @x = @XML;   
    END TRY   
    BEGIN CATCH     
    	SET @stringXML = ERROR_MESSAGE();   
    END CATCH    
    RETURN;   
    

    END


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.