SQL Server Error - Msg 9412, Level 16, State 1

We will get this error when we are trying to query XML in SQL Server. If that XML is invalid, Say for example if the closing tag ">" is missed in the input XML

Below error message will be throwed :

Msg 9412, Level 16, State 1, Line 1
XML parsing: line 6, character 5, '>' expected


To resolve the error:


DECLARE @X XML = '
<row>
<name>spt_fallback_db</name>
<schema_id>1</schema_id>
<type_desc>USER_TABLE</type_desc>
</row' 

SELECT @X

 


Check if the XML tags are properly enclosed to fix / avoid this error.

  Note: This error can also be encountered under various other scenarios. I will keep updating this article.

SELECT * FROM Sys.messages WHERE language_id = 1033 AND message_id = 9412


See Also:

No comments: