I have a query returning large XML, its size can reach 1GB in extreme cases, but normally it takes hundreds of megabytes.
The obvious approach when client program receives all the data at once and keeps it in memory doesn’t work in this case.
Is there any way to make SQL Server output result into a file? Or maybe it could deliver resulting data piece by piece? In the latter case it would be trivial to direct the ouput to a file without loading everything to memory.
According to the statement of problem the resulting XML is to be transformed by XSLT which would produce much smaller result. Ideally the server should be instructed to output XML data into a pipe which could be connected to xslt engine being run as a separate process. However I don’t see any way to do this.
Are there any ideas?
Thank you.
Client program is to be written in C# 3.
SQL Server version is 2005, however if some really good solution exists in 2008 only, this restriction should not be considered essential
Assuming you are using a .NET language and ADO.NET, here
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson02.aspx
you find a example how to feed the result set of a SELECT SQL to the Console stream using an SqlDataReader. Replace the Console by a file stream and you are done.
Unfortunately, that works only if your XML is stored in several text rows, line-by-line. If your XML is stored in a BLOB field, you need some kind of chunking. Read this article how to do this:
http://support.microsoft.com/kb/317034/EN-US