I need to return my result set in XML and this works fine, but if the number of records are increased, my xml output is truncated
here is my query
I know this question was asked like 10 Years ago, but still if someone is looking for a workaround which doesn't require any changes in the DB side and is a bit similar to the Accepted answer but not with SqlDataReader
.
You could make use of a DataTable
and fill it using the SqlDataAdapter
. Where your XML
data will be divided into multiple rows.
For Example
string xmloutput = "";
var cmd = new SqlCommand("<some sql query that returns data in xml format>", con);
var da = new SqlDataAdapter(cmd);
var dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
foreach (DataRow dr in dt.Rows)
{
xmloutput += dr[0].ToString();
}
Note:
DB
with XML
data in it.And later on, make use of the variable xmloutput
.
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