HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Howto avoid textdata of trace gets truncated?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
textdatahowtotruncatedavoidtracegets

Problem

I have a trace file including the TEXTDATA column created by a server-side tracing.
Some of the traced queries are very long.

If I re-open the trace file on Profiler, the relevant long query is displayed completely - it has 340 rows of text and 10951 characters.

But after I have imported the trace file into a SQL-Server table, the relevant query seems to be truncated. The table has a ntext column that had been created by the fn_trace_gettable method.

I queried the table using different methods:
The text output in SSMS (with maximized number of characters configured) interrupts the output at line 52.
The file output of SSMS (*.rpt) also truncates, here the query is getting truncated at line 250.

So right now I wonder if it's possible to get the WHOLE query out of the trace file into a SQL-Server table and how?

Solution

SSMS always truncates long strings unless typed as XML in which case you can set it to allow unlimited.

The workaround I usually use (from Adam Machanic's workaround to a connect item (internet archive link)) is below

SELECT (SELECT YourTraceDataColumn AS [processing-instruction(x)] FOR XML PATH(''), TYPE)
FROM YourTraceTable


This adds a few leading (``) characters but otherwise leaves the data intact and without characters being replaced by XML entities.

Code Snippets

SELECT (SELECT YourTraceDataColumn AS [processing-instruction(x)] FOR XML PATH(''), TYPE)
FROM YourTraceTable

Context

StackExchange Database Administrators Q#140721, answer score: 8

Revisions (0)

No revisions yet.