XML Output is Truncated in SQL

蹲街弑〆低调 提交于 2019-11-28 23:08:10

I've had the same problem with management studio and xml result sets. I've solved this by getting the output programatically with c#, with SqlDataReader.

user3791994

Try the following:

Declare @xmldata xml
set @xmldata = (select ... From test for xml...)
select @xmldata as returnXml

I had the same issue. I changes my Query result setting to Unlimited, but it didnt work. There is a work around. Its not very neat, but if you do want to continue to use SQL Server Management studio and get the results. Tweak the query to convert the xml stored using:

convert(xml,'<xml><![CDATA[' + cast(MyColumnWithXml as varchar(max)) + ']]></xml>') 

The complete text is returned. Please note you will have to do some formatting at you end

This worked for me (SSMS 2012): Tools > Options > Query Results > SQL Server > Results to Grid: Maximum Characters Retried: XML data: Unlimited. Then I saved the results of the grid to a file.

If your XML result set is still being truncated even after changing SSMS Options, use the SQLCMD utility with :XML ON option prior to running your XML statement. Direct your output to a file using the -o switch. SQLCMD is a command line utility that is very simple to use. See http://msdn.microsoft.com/en-us/library/ms162773.aspx.

The XML output you get in Query output window is not really intended for saving valid XML documents. You can get valid XML out of SQL Server when you capture it as a stream using ADO or SQLXML managed classes in .NET

However you can limit the query output sizes by using In SQL Server Management Studio go to Tools >> Options >> Query Results >> SQL Server >> Results to Text >> Maximum number of characters displayed in each column

You can use SQL Management Studio for 2008 against a SQL Server 2005 database engine. If you do that, the defaults should be large enough, but in Tools -> Options -> Query Results -> SQL Server there is a Results to Grid and Results To Text node.

Results to Grid allows you to control the maximum size for XML data explicitly, and the default maximum size is 2MB.

If you don't have a license for SSMS 2008 you should be able to use the express edition for free here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!