getting traceid parameter output using ADO | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

getting traceid parameter output using ADO

Hi,<br /> I am in a process of creating a trace event class using ADO . These are the statements to create a trace event.<br /><br /> –&gt;DECLARE @TraceIdOut int <br /><br /> –&gt;Exec sp_trace_create @traceid= @TraceIdOut OUTPUT , @options = 2 <br /> ,@tracefile =N’C:program FilesNetIQ empLoginFailures2_1139318214.trc'<br /><br /> –&gt<img src=’/community/emoticons/emotion-4.gif’ alt=’;P’ />RINT @TraceIdOut<br /><br /> this returns the traceid allocated to the trace event. <br /><br /><br /><br /> The steps I followed to create an event using ADO are as below:<br /><br />ADO::_ConnectionPtrpConn(__uuidof(ADO::Connection));<br />ADO::_RecordsetPtrprsResults(__uuidof(ADO::Recordset));<br /><br /><br /> pConn-&gt;ConnectionString =xxxxxx<br /> pConn-&gt;Open(xxxx);<br /><br /> prsResults-&gt;Open("DECLARE @TraceIdOut int
Exec sp_trace_create @traceid= @TraceIdOut OUTPUT , @options = 2 ,@tracefile =N’C:xx.139318214.trc’
PRINT @TraceIdOut");<br /><br /><br />The statement is getting executed propely and I am trace event is being created in the sql server 2005 . <br /><br />NOw the problem is I dont know how to retrieve the returned trace Id from the record set. <br /><br />Any suggessions regarding this will be highly appreciated.<br /><br />Thanks in advance.<br /><br /><br /><br /><br /> <br />
The problem is, you are PRINTing the traceid. PRINTed output is handled differently by ADO, I think its returned in the ErrorMessage Collection (or something similar, I dont remember). Unless you have a good reason to PRINT it, Id recommend you simply SELECT it, then you can pick it up from ADO as a normal resultset.
Dear Chappy ,<br /> I used select statement (select @TraceIdOut[TraceId]) to return the value. I could get the value using recordSetPtr-&gt;Fields-&gt;Items["TraceId".<br /><br />Thanks for your help chappy <img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />. <br /><br /><br />Regards,<br />Satish<br /><br /><br />