views:

291

answers:

5

I am trying to return Xml value from SQL Server 2005 using For Xml. Is there any limit in the size of xml returned from SQL Server?

I will be using ExecuteXmlReader to get the value in my C# code.

Also, is there any limit on the data that can hold in an XmlReader?

Any thoughts...

A: 

No, there's no limit. But it should be obvious that if you return many megabytes of data, the speed of data retrieval will suffer.

Frans Bouma
+4  A: 

There is no practical limit, but you are normally returning the equivalent of nvarchar(MAX), so you're likely to run into a ~2 billion character limit (and probably much less then that because of limited free address space).

However there are no small limits, like the 32KB SQL statement limit, that you need to worry about.

David
A: 

With SQL 2005 and .Net 2.0 Microsoft do not publish a limit, but in practise large-ish result sets can fail with 'out of memory' errors etc

For XML puts a extra load on the DB server, are you sure you wouldn't be better of processing the raw data into XML on an application server or client?

TFD
SQL 2000 had a client side xml provider library which offloaded the processing of the For Xml results to the client machine. this was released as part of a Feature Pack.
JoshBerke
+1  A: 

Make sure to use the following code:

while(xmlReader.Read()){ 
...
}

otherwise you might end up having invalid XML if your XML document is too big to fit into one record. SQL Server will spread it up over multiple records so to day,...

Roel Snetselaar
Does that mean, if the SQL Server can't load the entire data in one go, it will return multiple times?
renil
It will return multiple rows. Concatenating the rows will give you valid XML.
Roel Snetselaar
+2  A: 

Technically there is a 1 Gig limit as the XML datatype is based off of the NVARCHAR(MAX) data type. But if you have a 1 Gig XML document you need to look at making it smaller.

mrdenny