XML Output is Truncated in SQL

后端 未结 8 1728
挽巷
挽巷 2020-12-09 03:44

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



        
相关标签:
8条回答
  • 2020-12-09 04:16

    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:

    • the above code assumes that the only one column is returned from DB with XML data in it.

    And later on, make use of the variable xmloutput.

    0 讨论(0)
  • 2020-12-09 04:19

    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

    0 讨论(0)
提交回复
热议问题