"Msg 6602" error when you execute the sp_xml_preparedocument stored procedure in SQL Server 2008, SQL Server 2008 R2, or SQL Server 2012

Applies to: SQL Server 2008 DeveloperSQL Server 2008 EnterpriseSQL Server 2008 R2 Datacenter


When you try to execute a sp_xml_preparedocument stored procedure in Microsoft SQL Server 2008, SQL Server 2008 R2, or Microsoft SQL Server 2012 in which the content of the xmltext parameter is a complex XML document, you receive an error message that resembles the following:

The XML parse error 0x80004005 occurred on line number 1, near the XML text "<XML document sample>"
Msg 6602, Level 16, State 2, Procedure sp_xml_preparedocument, Line 1
The error description is 'Unspecified error'.


This issue occurs because of a design limitation of the MSXML parser (Msxmlsql.dll) that SQL Server uses.

The issue is not strictly related to the size of the XML document but to its complex structure. A combination of the XML element's structure depth, the number and size of attributes, and the number of entities within attributes can cause this issue. However, the level of complexity that is required to reach this limit is usually found in XML documents that are several megabytes.


To work around this issue, try to reduce the complexity of the XML document.

Note Beware of very large single string attributes that contain many XML &#xA; entities.


Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.