Sql Server 2008 Standard:
To isolate the problem I'm having, I've created a simple Dbs with just one
table, having an "int" field and an "xml" field.
The xml field is assigned to a SchemaCollection, so it is typed.
Updating the xml field with XML data works 99.99 of the times, but I have 2 specific XML fragments that systematically give me problems. Updating the xml field in the table with this data works fine without errors, however when I do a SELECT * from the table in the Management Studio, I get the error:
"An error occurred while executing batch. Error message is: Index was outside the bounds of the array."
Changing "SELECT xmlField FROM tab" to "SELECT CAST(xmlField AS nvarchar(MAX)) FROM tab" appears to give me the correct xml string, so the data is there!
Querying the data from .Net code gives the same error. Here's part of the stack trace:
[IndexOutOfRangeException: Index was outside the bounds of the array.]
System.Xml.XmlSqlBinaryReader.GetXsdKatmaiTokenLength(BinXmlToken token) +1207761
System.Xml.XmlSqlBinaryReader.ScanOverAnyValue(BinXmlToken token, Boolean attr, Boolean checkChars) +524
System.Xml.XmlSqlBinaryReader.ScanOverValue(BinXmlToken token, Boolean attr, Boolean checkChars) +159
System.Xml.XmlSqlBinaryReader.ImplReadData(BinXmlToken tokenType) +119
I get this exact problem on different machines: both the production Server 2003 and my Vista development PC.
The funny thing is that if I remove a few things from the XML, and re-update, the error goes away, but there's no structure in what I have to remove. As if the XML content is triggering some rare bug in the Sql server code?
I've been successfully using XML fields in SQL2005 for 3 years now, and have recently upgraded to SQL2008.
This has me completely puzzled.
Is there any known problem that might be related or anyone has a clue how to fix this? Would be warmly appreciated.
OK, I have managed to create a "repro" script.
Just download the following:
Contains only 1 file: SqlRepro.sql
Run this script on any SQL Server 2008 (I use the Standard version).
What the script does:
1. Create a new database: "FdmSqlRepro" (drops it first if already exists)
2. Create a schema collection: "MySchemaCollection"
3. Create a table: "TestTable", with a numeric "idx" column and a typed xml column "xData". The xml column is bound to the created "MySchemaCollection"
4. Insert 1 record in the table
5. Query the table (SELECT * FROM TestTable)
The last step (query *) gives the error:
"Index was outside the bounds of the array."
Can anyone run this script and confirm they get the same error?
And then of course: why ... ?
Hopefully my question is a little more documented now.
Thanks, I have done that. It's now 2 weeks ago but it seems that will not exactly be the fast track to a solution. Seems like the report will be sitting there with no feedback from Microsoft.
Any other actions I could take to get at least some acknowledgment from Microsoft?
This bug (?) is a bit like a time-bomb for our application: any newly added record could induce the error again and prevent running queries on the table until the record is removed.