0

I have a trouble. :(

MS SQL Server 2016 13.0.15900.1 .NET Framework 4.5.2

  • There is a table with large xml fields (> 1 mb)
  • A terrible procedure which read, change and update [xmlField] with(out) XPath
  • The procedure selects [xmlField] from [myTable] where [id] = @id
  • And a dynamic SQL-request with (readuncommitted, nolock).

The terrible procedure and the dynamic request working fine. The procedure which selects [xmlField] leads to NullReferenceException in the System.Data.dll

Object reference not set to an instance of an object.   at System.Xml.XmlSqlBinaryReader.ScanAttributes()
   at System.Xml.XmlSqlBinaryReader.ImplReadElement()
   at System.Xml.XmlSqlBinaryReader.ReadDoc()
   at System.Xml.XmlSqlBinaryReader.Read()
   at System.Xml.XmlWriter.WriteNode(XmlReader reader, Boolean defattr)
   at System.Data.SqlTypes.SqlXml.get_Value()
   at System.Data.SqlClient.SqlDataReader.GetValue(Int32 i)
   at System.Data.SqlClient.SqlCommand.CompleteExecuteScalar(SqlDataReader ds, Boolean returnSqlValue)
   at System.Data.SqlClient.SqlCommand.ExecuteScalar()

What the hell is going on and how I can avoid it?

Probably, we read only a part of XML, which did not have time to enroll to the end, which leads to corrupt of the xml-document. But how then can this be circumvented? Working with XML as a string?

Lunar Whisper
  • 210
  • 1
  • 6
  • With readuncommited you can read damaged xml blob, which is probably what happens here, so just use higher isolation level? – Evk Nov 09 '17 at 08:35
  • @Evk With readuncommited - yes. But as I say I was got a corrupted xml via stored procedure **without** this modificator. – Lunar Whisper Nov 09 '17 at 09:10

0 Answers0